我想在一个页面上为多个画廊初始化漂亮的照片插件,以便它们可以单独显示。我的想法是遍历所有包含图片的div,并为该div 中的所有图像初始化新prettyPhoto
。但是val
显然是某种对象,我无法对其调用任何函数。有没有办法做我需要的事情?
$(document).ready(function() {
$.each($(".gallery"), function(i, val) {
$(val).find("img").prettyPhoto({}); //init prettyPhoto plugin
});
});
附言对不起,蹩脚的问题我想这是基本的东西。
我终于找到了解决方案,以防有人感兴趣。
$(document).ready(function(){
$.each($(".gallery"), function(i, val) {
var queryString = ".gallery:nth(" + i + ") a[rel^='prettyPhoto']";
$(queryString).prettyPhoto({animation_speed:'normal',theme:'light_square', social_tools: false});
});
});