2011-06-02 86 views
0

我使用流行的jQuery scrollTo/localScroll插件來創建一個單一的頁面導航系統,自動滾動窗口到各種錨標籤。我有它沒有問題,但我無法阻止排隊動畫。localscroll jQuery插件 - 動畫排隊問題

我有一個無序列表的「main_nav」的ID,我現在用跳到錨點:

<ul id="main_nav"> 
    <li><a href="#one">One<a> </li> 
    <li><a href="#two">Two</a></li> 
    <li><a href="#three">Three</a> </li> 
    <li><a href="#four">Four</a> </li> 
</ul> 

當調用功能,有一個名爲「停止」參數,它應該是通過jquery stop()函數清除當前排隊的動畫。該參數在插件中默認爲「true」,但我仍然指定了它。該插件還默認將該窗口作爲滾動目標。我打電話的功能,像這樣:

$(document).ready(function() { 
    $('#main_nav').localScroll({ 
    duration:2000, 
    stop:true 
    }); 
}); 

這工作,但「停止」參數被忽略......如果我點擊快速連續四個環節,頁面會後,其他滾動到每一個環節,總共需要8秒鐘才能完成。不理想!如果我把整個頁面包裝在一個容器div中,給它一個高度,並將其設置爲溢出:scroll;然後使用localScroll函數定位該div,然後停止參數起作用。例如,當這樣調用沒有更多的動畫隊列:

$(document).ready(function() { 
    $('#main_nav').localScroll({ 
    target: $('#container'), 
    duration:2000, 
    stop:true 
    }); 
}); 

看來,當插件引用一個div作爲目標進行滾動,它能夠執行的jQuery stop()函數,但是當目標設置爲'窗口'停止功能不起作用。

我試圖創建一個jQuery包裝器窗口對象和引用,作爲目標,像這樣:

$(document).ready(function() { 
    $('#main_nav').localScroll({ 
    target: $('window'), 
    duration:2000, 
    stop:true 
    }); 
}); 

...但是這也不管用。在插件本身,默認值是:

$localScroll.defaults = { 
    duration:1000, // How long to animate. 
    axis:'y', // Which of top and left should be modified. 
    event:'click', // On which event to react. 
    stop:true, // Avoid queuing animations 
    target: window, // What to scroll (selector or element). The whole window by default. 
    reset: true // Used by $.localScroll.hash. If true, elements' scroll is resetted before actual scrolling 
}; 

有沒有人對如何從cueueing停止動畫任何想法?

我使用: 的jQuery 1.6.1,1.4.2 scrollTo,localScroll 1.2.7

回答

0

我已經嘗試

$('.menu, .up, #send, #ok').localScroll({ 
    duration: 1800, 
    stop: true, 
    hash: true, 
    onBefore: function(e, elem, $target) { // this = settings 
     $target.stop(); 
    } 
    }); 

但這dons't工作要麼

..然後我認爲這可能是jQuery版本問題(scrollTo和休息是從2009年),所以我已經回到jquery 1.2.6,仍然沒有,所以我想這可以是一個scrollTo插件問題

現在我會嘗試寫自己的scrollTo插件只使用.animate()

0

我發現了!

我不知道爲什麼對象窗口不能動畫! 在控制檯:

$(window).animate({ scrollTop: 110}, 1000); 
TypeError 
$('body').animate({ scrollTop: 110}, 1000); 
[ 
<body>​…​</body>​ 

爲了解決這個問題,只是簡單地改變目標體

target: $('body') 

,這是它:)

+0

*我已經在動畫Window對象沒有問題。問題在於,當用戶快速連續點擊幾個鏈接時,動畫就會被提示。當目標設置爲$('window')時,添加'stop'參數不起作用。當目標被更改爲$('body')時,問題仍然存在...... – 2011-08-16 09:35:51

+0

我在調整窗口大小時滾動窗口時出現此問題,而這根本無法解決問題。 – 2011-11-13 08:54:49