jQuery内容滚动条

时间:2013-07-26 09:21:47

标签: jquery html

当我们将鼠标悬停在“向上”“向下”按钮上时,

“内容滚动” 演示:http://jsfiddle.net/s5mgX/1657/

我的问题是 - 我还需要在内容区域滚动鼠标时“内容滚动”吗?

var step = 25;
var scrolling = false;

// Wire up events for the 'scrollUp' link:
$("#scrollUp").bind("click", function(event) {
    event.preventDefault();
    // Animates the scrollTop property by the specified
    // step.
    $("#content").animate({
        scrollTop: "-=" + step + "px"
    });
}).bind("mouseover", function(event) {
    scrolling = true;
    scrollContent("up");
}).bind("mouseout", function(event) {
    scrolling = false;
});


$("#scrollDown").bind("click", function(event) {
    event.preventDefault();
    $("#content").animate({
        scrollTop: "+=" + step + "px"
    });
}).bind("mouseover", function(event) {
    scrolling = true;
    scrollContent("down");
}).bind("mouseout", function(event) {
    scrolling = false;
});

function scrollContent(direction) {
    var amount = (direction === "up" ? "-=1px" : "+=1px");
    $("#content").animate({
        scrollTop: amount
    }, 1, function() {
        if (scrolling) {
            scrollContent(direction);
        }
    });
}

由于

1 个答案:

答案 0 :(得分:1)

您需要的是jQuery Mousewheel插件。

您可以在此处下载:

https://github.com/brandonaaron/jquery-mousewheel

只需在页眉上的常规jQuery libray之后添加引用。