Created
November 12, 2012 06:09
-
-
Save pottava/4057780 to your computer and use it in GitHub Desktop.
サーバアクセスなしにローカルファイルを背景画像に適用するjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// change BgImage by the input file's attribute without any server access. | |
document.querySelector('input[type="file"]').addEventListener('change', function (e) { | |
var reader = new FileReader(); | |
reader.onload = function(e) { | |
$('#backgroundId').css({backgroundImage:'url("'+e.target.result+'")'}); | |
}; | |
reader.readAsDataURL(e.target.files[0]); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment