问题描述
我目前正在开发一个小型产品显示页面,通过ajax加载相当于PhotoPlus的画廊。问题是,prettyPhoto不会在最初加载页面之后添加的图像。我明白,在新内容加载后,我需要重新初始化prettyPhoto,但是如何?我试过添加prettyPhoto.init();到返回到页面的代码 - 这不起作用。
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.
页面正在处理中:
推荐答案
我最终找到了两个解决方案第一个也是最好的是把这一点放在一起:
I ended up finding two solutions. The first and best was to put this whole bit:
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
进入ajax回调,而不是 prettyPhoto.init();
函数我以前在调用。
into the ajax callback, not the prettyPhoto.init();
function I was calling before.
我也有一些运气使用API,而不是重新加载prettyPhoto。
I also had some luck with using the API instead of re-loading prettyPhoto again.
希望这有助于某人。
这篇关于prettyPhoto和Ajax加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!