最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - prettyPhoto and Ajax-loaded content - Stack Overflow

programmeradmin0浏览0评论

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: .php?id=10

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./page.php?id=10

Share Improve this question asked Oct 18, 2009 at 6:23 SteveSteve 711 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

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.

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(); 
}
$(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();  
});
});
发布评论

评论列表(0)

  1. 暂无评论