prettyPhoto and Ajax-loaded content

喜夏-厌秋 提交于 2019-12-24 04:14:05

问题


I'm currently working on a little product display page that loads prettyPhoto-enabled galleries through ajax. The problem is, prettyPhoto doesn't work on the images added after the page loads initially. I understand that I need to re-initialize prettyPhoto after the new content loads, but how? I've tried adding prettyPhoto.init(); to the code that is returned to the page - that doesn't work.

Page I'm working on is here: http://turningpointpro.com/page.php?id=10


回答1:


I ended up finding two solutions. The first and best was to put this whole bit:

$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto();
});

into the ajax callback, not the prettyPhoto.init(); function I was calling before.

I also had some luck with using the API instead of re-loading prettyPhoto again.

Hope this helps someone.




回答2:


If you are using ASP.NET with Ajax, the scriptmanager will allow you to use a function called pageLoad() that is called every time the page posts back (async or otherwise).

your code:

function pageLoad()
{
 $("a[rel^='prettyPhoto']").prettyPhoto(); 
}



回答3:


$(function() {
$('#navigation a.button').click(function(e) {
  $.get( $(this).attr('href'), function(data) {
      $('#portfolio').quicksand( $(data).find('li'), { adjustHeight: 'dynamic' }, function(){ $("a[rel^='prettyPhoto']").prettyPhoto(); } );

  });  
  e.preventDefault();  
});
});


来源:https://stackoverflow.com/questions/1584167/prettyphoto-and-ajax-loaded-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!