2012-02-26 32 views
2

我該如何做?鼠標輸入時保持滾動狀態

$('#forward').mouseenter(
     function() { 
      $("#scroller").trigger("slideTo", [1, "next"]);   
     } 
    ); 

    $('#backward').mouseenter(
     function() { 
      $("#scroller").trigger("slideTo", [1, "back"]);   
     } 
    ); 

它應該保持滾動而我的鼠標按鈕的頂部,只會停止滾動,當我的鼠標按鈕之外。顯然它只會滾動一次然後停止。我需要將按鈕懸停激活,以便用戶不會繼續點擊按鈕。

參考:http://caroufredsel.frebsite.nl/code-examples/custom-events.php

回答

2

我相信你正在尋找這個http://jsfiddle.net/DNcAS/3/

$("#foo2").carouFredSel({ 
    auto : { 
     button   : "#foo2_play" 
    }, 
    scroll : { 
     items   : 1, 
     duration  : 1000, 
     pauseDuration : 0 
    } 
}).trigger("pause"); 


$('#foo2_next').mouseenter(
     function() { 
      $("#foo2").trigger("configuration", ["direction", "left"]) 
         .trigger("play"); 
     }).mouseleave(function(){ 
      $("#foo2").trigger("pause"); 
     }); 

$('#foo2_prev').mouseenter(
     function() { 
      $("#foo2").trigger("configuration", ["direction", "right"]) 
         .trigger("play"); 
     }).mouseleave(function(){ 
      $("#foo2").trigger("pause"); 
     });​ 

對於線性滾動修改配置選項http://jsfiddle.net/DNcAS/4/

scroll : { 
    items   : 1, 
    duration  : 1000, 
    easing   : "linear", 
    pauseDuration : 0 
} 

或者您也可以通過hoverhttp://jsfiddle.net/DNcAS/5/

更換 mouseentermouseleave

PS:更短的版本http://jsfiddle.net/DNcAS/6/

$('#foo2_next,#foo2_prev').hover(function() { 
      var dir = $(this).hasClass('next') ? 'left' : 'right'; 
      $("#foo2").trigger("configuration", ["direction", dir]) 
         .trigger("play"); 
     }, function(){ 
      $("#foo2").trigger("pause"); 
     }); 
+0

是的,這正是我所期待的。謝謝! – Pennf0lio 2012-02-26 23:57:18

+0

@ Pennf0lio你可以使它更短http://jsfiddle.net/DNcAS/6/ – Cheery 2012-02-27 00:28:53

0

你的意思是這樣的?

var forwardInterval; 
$('#forward').mouseenter(
    function() { 
     forwardInterval = setInterval(function() { 
      $("#scroller").trigger("slideTo", [1, "next"]);   
     }, 1000); 
    } 
); 
$('#forward').mouseleave(
    function() { 
     clearInterval(forwardInterval); 
    } 
); 
+0

嗨梅德諾根,感謝您的回答,但我不知道爲什麼它不工作我。它正確地調用該功能,但不會持續觸發。它只運行一次。 – Pennf0lio 2012-02-26 22:33:19

+0

嘗試使用'prev'和'next'自定義事件而不是'slideTo'... – 2012-02-26 22:54:34

相關問題