0

So I am trying to add another css class called popup to an .each function.

jQuery:

$.each(data.photos.photo, function(i, photo) {
        var imgURL = 'http://farm' + photo.farm + '.staticflickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret + '_n.jpg';

        console.log(imgURL);

        // Pre-cache image
        $('<img />').attr({'src': imgURL, 'data-image-num': i}).load(function() {
           console.log('image loaded');
           var imageDataNum = $(this).attr('data-image-num');
           $('#photo-' + imageDataNum).css('background-image', 'url(' + imgURL + ')').removeClass('fade-out').addClass('fade-in');
        });

     });

CSS

.popup
{
position:absolute;
top:0px;
left:0px;
margin:100px auto;
width:200px;
height:150px;
font-family:verdana;
font-size:13px;
padding:10px;
background-color:rgb(240,240,240);
border:2px solid grey;
z-index:100000000000000000;
display:none
}

Thank you for your help and this is my frist post by the way so sorry if i sound nooby.

4

1 回答 1

0
...
$('#photo-' + imageDataNum).css('background-image', 'url(' + imgURL + ')').removeClass('fade-out').addClass('fade-in').addClass('popup');
...

或者

    $('<img />').attr({'src': imgURL, 'data-image-num': i}).load(function() {
       console.log('image loaded');
       var imageDataNum = $(this).attr('data-image-num');
       $('#photo-' + imageDataNum).css('background-image', 'url(' + imgURL + ')').removeClass('fade-out').addClass('fade-in');
    }).addClass('popup');
于 2013-10-26T00:36:03.477 回答