为静态内容和通过ajax加载的内容调用一次jQuery插件

时间:2013-03-08 17:50:16

标签: jquery ajax flexslider

我正在使用两个jQuery插件:easytabs和prettyPhoto。我想在(1)静态页面上使用prettyPhoto插件,在(2)图像上使用easytabs插件通过ajax加载。

这就是我现在正在做的事情(请注意,这样做很好,但我想知道是否有更有效的方法):

$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto(); // Calling prettyPhoto for the first time (for images on the static page)

    $('#portfolio-tabs').easytabs();
    $('#portfolio-tabs').bind('easytabs:ajax:complete', function() {
        $("a[rel^='prettyPhoto']").prettyPhoto(); // Calling this again for it to work on images loaded via ajax
    )
});

1 个答案:

答案 0 :(得分:0)

我相信加载的easytabs内容会在portfolio-tabs中呈现,然后将ajax回调更改为

var tabs = $('#portfolio-tabs').bind('easytabs:ajax:complete', function() {
    $("a[rel^='prettyPhoto']", tabs).prettyPhoto(); // Calling this again for it to work on images loaded via ajax
)
相关问题