2013-04-03 51 views
0

我使用jQuery Mobile的,我有一堆就是這個樣子如何在pageshow調用相同的代碼並滾動頂部

$(document).on("pageshow", function() { 
    $(function() { 
    var $container; 
    $container = $(".items-section"); 
    return $container.imagesLoaded(function() { 
     $container.masonry({ 
     itemSelector: "article.hlisting" 
     }); 
     return $container.masonry({ 
     isFitWidth: true 
     }); 
    }); 
    }); 
}); 

執行JavaScript代碼的,但因爲我檢索通過AJAX和重繪對象他們在屏幕上,一些相同的代碼還需要在內部執行$(document).on("scrollstop", function()

我的問題是。我如何重構代碼以便在兩種情況下被調用?

回答

3

如果這正是你想要被稱爲然後就通過多個空格分隔的事件作爲第一個參數相同的代碼:

$(document).on("pageshow scrollstop", function() { 
    // your code here 
});