1

当我们将鼠标悬停在“向上”“向下”按钮上时“内容滚动”演示: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);
        }
    });
}

谢谢

4

1 回答 1

1

你需要的是jQuery Mousewheel插件。

你可以在这里下载:

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

jQuery并且只需在页眉上的常规库之后添加一个引用。

于 2013-07-26T09:25:44.450 回答