jquery - Load image into appended element -


i having problem trying load image after element has been appended when thumbnail has been clicked on, replace /t/ /i/ loads appended element code:

$('.main-image img').live('click', function () {  var image_url = $(this).attr('src');  var loadurl = image_url.replace(/\/t\//, '/i/');   $('.container').slideup('slow');   $('#pop-up').append('<div class="container tcenter"><p id="close-preview" class="link tcenter">close</p><div class="quick-view"><img src="img/loading.gif" /></div></div>', function()  {   $('<img />').attr('src', loadurl).load(function()   {             $('.quick-view').empty();    $(this).appendto('.quick-view');   });  });      // ignore part - above needs helping  $('.quick-view').css('line-height', ($('.quick-view').parents().find('.container').height() - 25) + 'px');  $('.container:last').css('background', '#fff');  $('.container:last img').css('max-height', $(window).height() * 75 / 100) }); 

however, doesn't seem work shows loading image, there particular wrong code doesn't load image appended element...

edit:

$('.main-image img').live('click', function () {     var image_url = $(this).attr('src');     var loadurl = image_url.replace(/\/t\//, '/i/');     var self = $(this);      $('.container').slideup('slow');      $('#pop-up').append('<div class="container tcenter"><p id="close-preview" class="link tcenter">close</p><div class="quick-view"><img src="img/loading.gif" /></div></div>', function()     {         $('<img />').attr('src', loadurl).live('load', function()         {             self.fadeout('slow', function()             {                 self.empty(function()                 {                     self.appendto('.quick-view');                 });             });         });     });     $('.quick-view').css('line-height', ($('.quick-view').parents().find('.container').height() - 25) + 'px');     $('.container:last').css('background', '#fff');     $('.container:last img').css('max-height', $(window).height() * 75 / 100) }); 

i think you're after:

$('.main-image img').live('click', function () {     var loadurl = this.src.replace(/\/t\//, '/i/');     $('.container').slideup('slow');      $('#pop-up').append('<div class="container tcenter"><p id="close-preview" class="link tcenter">close</p><div class="quick-view"><img src="img/loading.gif" /></div></div>');      $('<img />').load(function() {        var img = this;        $('.quick-view img').fadeout('slow', function() {          $(this).replacewith(img);        });     }).attr('src', loadurl);      $('.quick-view').css('line-height', ($('.quick-view').closest('.container').height() - 25) + 'px');     $('.container:last').css('background', '#fff');     $('.container:last img').css('max-height', $(window).height() * 75 / 100) }); 

basically you're passing callback numerous functions don't accept function. above loads image in background, , when it's finished fade out loader image replaces loaded one.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -