jquery.load()之后的同位素

时间:2014-02-14 09:43:32

标签: jquery ajax wordpress jquery-load


我正在尝试在wordpress上使用ajax(正确的jQuery .load()函数)但我有一个问题因为页面加载同位素后不起作用。 有谁知道如何解决这个问题?
谢谢!
这是我的整个代码:

var $j = jQuery.noConflict();

//Isotope
$j(document).ready(function($){
    $j('#container').isotope({
          itemSelector: '.thumbportfolio',
          layoutMode: 'fitRows'       
          });
    });

$j(document).ready(function(){
    $j('#filters a').click(function(){  
      var selector = $j(this).attr('data-filter');
      $j('#container').isotope({ filter: selector });
      return false;
}); 
}); 

/* AJAX */
$j(function() {
    var $mainContent = $j("#content"),
    URL = '',
    siteURL = "http://" + top.location.host.toString(),
    $internalLinks = $j("a[href^='"+siteURL+"']"),
    hash = window.location.hash,
    $ajaxSpinner = $j("#content"),
    $el, $allLinks = $j("a");

    $internalLinks.each(function(){
        $j(this).attr("href", "#" + this.pathname);
    }).click(function($){
        $ajaxSpinner.fadeIn();
        $mainContent.animate({"opacity": "0.1"});
        $el = $j(this);
        $j(".current_page_item").removeClass("current_page_item");
        URL = $el.attr("href").substring(1);
        URL = URL + " #content";
        $allLinks.removeClass("current_link");
        $mainContent.load(URL, function(){
            $el.addClass("current_link").parent().addClass(".current_page_item");
            /*$ajaxSpinner.fadeOut();*/
            $mainContent.animate({ opacity: "1"});
        });
    });
});

1 个答案:

答案 0 :(得分:1)

我这样解决了:

/* AJAX */
$j(function() {
    var $mainContent = $j("#content"),
    URL = '',
    siteURL = "http://" + top.location.host.toString(),
    $internalLinks = $j("a[href^='"+siteURL+"']"),
    hash = window.location.hash,
    $ajaxSpinner = $j("#content"),
    $el, $allLinks = $j("a");

    $internalLinks.each(function(){
        $j(this).attr("href", "#" + this.pathname);
    }).click(function($){
        $ajaxSpinner.fadeIn();
        $mainContent.animate({"opacity": "0.1"});
        $el = $j(this);
        $j(".current_page_item").removeClass("current_page_item");
        URL = $el.attr("href").substring(1);
        URL = URL + " #content";
        $allLinks.removeClass("current_link");
        $mainContent.load(URL, function(){
            $el.addClass("current_link").parent().addClass(".current_page_item");
            /*$ajaxSpinner.fadeOut();*/
            $mainContent.animate({ opacity: "1"});
            $j('#container').isotope({
                  itemSelector: '.thumbportfolio',
                  layoutMode: 'fitRows'       
             });
            $j('#filters a').click(function(){  
              var selector = $j(this).attr('data-filter');
              $j('#container').isotope({ filter: selector });
              return false;
            });     
        });
    });
});