2012-03-26 53 views
0

我對jQuery插件smoothdivscroll的問題很少。Smooth Div Scroll - 滾動鼠標右鍵重置

本質上講,我試圖讓插件來爲這個頁面運行:http://www.smoothdivscroll.com/demo.html

不過,我有改變的JavaScript,因爲是需要自動滾動,但允許熱點工作爲好,但恢復自動滾動鼠標離開熱點。

雖然下面的代碼工作,在你離開右邊的觸發器之後,它'重置'回到第一個div。

是否有任何方法可以將其設置爲從設置位置恢復滾動?

代碼:

// Initialize the plugin with no custom options 
    $(document).ready(function() { 
     // I just set some of the options 
     $("div#makeMeScrollable").smoothDivScroll({ 
     mousewheelScrolling: true, 
     visibleHotSpotBackgrounds: "always", 
     autoScrollingMode: "endlessright" 
     }); 


    }); 
    //This is just to make the scroller pause... 
    $("#makeMeScrollable").bind("mouseover", function() { 
    $(this).smoothDivScroll("stopAutoScrolling"); 
    }).bind("mouseout", function() { 
    $(this).smoothDivScroll("startAutoScrolling"); 
}); 

回答

2

我不知道這是什麼原因導致你的問題,但你需要注意括號。代碼改成這樣:

// jQuery document ready 
$(document).ready(function() { 
    // Initialize the scroller 
    $("#makeMeScrollable").smoothDivScroll({ 
    mousewheelScrolling: true, 
    visibleHotSpotBackgrounds: "always", 
    autoScrollingMode: "endlessright" 
    }); 

    //This is just to make the scroller pause... 
    $("#makeMeScrollable").bind("mouseover", function() { 
    $(this).smoothDivScroll("stopAutoScrolling"); 
    }).bind("mouseout", function() { 
    $(this).smoothDivScroll("startAutoScrolling"); 
    }); 
}); // End query document ready 

我沒有測試此代碼,但除非我犯了一個錯字這是做了正確的道路。

祝你好運!

+0

感謝,但仍發瘋復位到第1格設置一次。但整齊的語法總是很好。 – 2012-03-27 08:41:59

+0

我很好奇,如果它是一個必須解決的錯誤,請看這個。你有一個測試頁的URL? – tkahn 2012-03-27 14:39:13

+0

http://www.vettacreative.co.uk/scroll/如果你也使用左側和右側的熱點,你會明白我的意思。謝謝 – 2012-03-30 09:50:54

0

我看到選項不對。試試這個(如果你使用的是最新版本,這是1.2版本):

// Initialize the scroller 
    $("#makeMeScrollable").smoothDivScroll({ 
    mousewheelScrolling: true, 
    visibleHotSpotBackgrounds: "always", 
    autoScrollingMode: "onstart", 
    autoScrollingDirection: "endlessloopright", 
    manualContinuousScrolling: true 
    }); 

在這種配置中,滾輪將在ensless循環正確加載時被自動滾動。只要用戶使用鼠標滾輪或熱點,自動滾動就會停止,如果不是您的自定義事件處理程序,則不會再次開始自動滾動。但是,既然你有他們,它應該在用戶離開可觸摸區域後立即重新開始。

我也設置了manualContinuousScrolling爲true,以便在手動滾動時獲得相同的無限循環。

這尚未經過測試,因此您可能需要做一些調整。例如,我不確定autoScrollingMode:「onstart」或autoScrollingMode:「always」是否是最佳選擇。你只需要嘗試。

0

我相信同樣重要的是,也許不同的版本會影響行爲。 這對我的工作:jquery.smoothDivScroll-1.1-min.js版本。

注意函數名的區別:stopAutoScroll與stopAutoScrolling等

$(window).load(function() { 
    $("#makeMeScrollable").smoothDivScroll({ 
     autoScroll: "always", 
     autoScrollDirection: "backandforth", 
     autoScrollStep: 1, 
     autoScrollInterval: 25, 
     startAtElementId: "startAtMe" 
    }); 

    //This is just to make the scroller pause... 
    $("#makeMeScrollable").bind("mouseover", function() { 
     $(this).smoothDivScroll("stopAutoScroll"); 
     }).bind("mouseout", function() { 
     $(this).smoothDivScroll("startAutoScroll"); 
    }); 
}); 
相關問題