【发布时间】:2014-08-01 19:51:59
【问题描述】:
我正在构建的页面上有多个水平滚动的 div。我希望它们彼此独立移动(当一个滚动时其他人保持不动)但现在它们都一起移动。
这是显示问题的基本代码的 jsfiddle:http://jsfiddle.net/2HxCH/2/
这是运行两个滚动条的 javascript:
(function () {
var scrollHandle = 0,
scrollStep = 5,
parent = $("#container, #container2");
//Start the scrolling process
$(".panner").on("mouseenter", function () {
var data = $(this).data('scrollModifier'),
direction = parseInt(data, 10);
$(this).addClass('active');
startScrolling(direction, scrollStep);
});
//Kill the scrolling
$(".panner").on("mouseleave", function () {
stopScrolling();
$(this).removeClass('active');
});
//Actual handling of the scrolling
function startScrolling(modifier, step) {
if (scrollHandle === 0) {
scrollHandle = setInterval(function () {
var newOffset = parent.scrollLeft() + (scrollStep * modifier);
parent.scrollLeft(newOffset);
}, 10);
}
}
function stopScrolling() {
clearInterval(scrollHandle);
scrollHandle = 0;
}
}());
我已经尝试了所有我能在 CSS 和 html 中想到的东西来将它们分开,所以我猜测修复是在 js 中。任何想法或建议都会很棒!
【问题讨论】:
标签: jquery scroll horizontal-scrolling