I'm having trouble trying to clone the string of a URL in the src= value of an . I'm trying to define the string as a variable so that I can append the "background-image" css value with said variable. ... Taking an and using it as a background-image in a
I'm doing so in a $(window).load event since I think the has to be rendered in the DOM in order for it's URL to be present. However, nothing seems to be working. I can alert(imgURL); but fail to plug it into the 's background.
Here's what I have so far. Any help would be greatly appreciated. Thanks!
$(window).load(function() {
var imgURL = $('.thumbnail img').each(function() {
$(this).attr('src');
});
$('.fullsize').each(function() {
$(this).css('background-image', 'url(' + imgURL + ')');
});
});
.fullsize {
width: 200px;
height: 200px;
}
.thumbnail img {
width: 75px;
height: 75px;
float: left;
cursor: pointer;
}
<div>
<div class="fullsize"></div>
<div class="thumbnail">
<img src="http://ift.tt/1KPPEIo" />
</div>
</div>
<div>
<div class="fullsize"></div>
<div class="thumbnail">
<img src="http://ift.tt/1RMfGBX" />
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire