Last active
December 20, 2015 03:39
-
-
Save AngeloMerlo/6065224 to your computer and use it in GitHub Desktop.
DRY - altera o background de uma div sem fazer upload da imagem (ha, pegadinha do malandro)
This file contains hidden or 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
$(document).ready(function(){ | |
// faz a leitura do arquivo e atualiza a div | |
function readURL(input,div) { | |
if (input.files && input.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
$(div).css('background-image', 'url(' + e.target.result + ')'); | |
} | |
reader.readAsDataURL(input.files[0]); | |
} | |
} | |
// quando mudar o valor do campo atualiza | |
$('[id^=arquivo_premio_]').change(function(){ | |
var id = $(this).attr('id').split("arquivo_premio_"); | |
readURL(this,'#imgPromo_'+id[1]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment