鼠标进入时保持滚动

keep scrolling when mouse enter

本文关键字:滚动 鼠标      更新时间:2023-09-26

如何做到这一点?

    $('#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

我相信你正在寻找这个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
}

也可以将mouseentermouseleave替换为hoverhttp://jsfiddle.net/DNcAS/5/

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"); 
        });

你的意思是这样的吗?

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