I have a DIV with overflow scroll. And i want to add 2 buttons to scroll that div UP and DOWN. I only can find a way to or scroll with the mouse. Or scroll with buttons, because they want me to set overflow on hidden.
Is there a way to do both?
I have a DIV with overflow scroll. And i want to add 2 buttons to scroll that div UP and DOWN. I only can find a way to or scroll with the mouse. Or scroll with buttons, because they want me to set overflow on hidden.
Is there a way to do both?
尝试这个:
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);
}
});
}