所以,我在div中得到了一些数据.它按日期分成几块.它使用jQuery和mousewheel插件水平滚动.
当div达到它的终点(最左边,最右边)时,我需要发射一个事件.我认为通过检测鼠标滚动插件中获取的数据,可以通过当前实现的方式来计算何时无法进一步滚动.我只需要朝着正确的方向轻推.这是为我进行水平滚动的代码:
$(document).ready(function () {
$('#timeline').mousedown(function (event) {
$(this)
.data('down', true)
.data('x', event.clientX)
.data('scrollLeft', this.scrollLeft);
return false;
}).mouseup(function (event) {
$(this).data('down', false);
}).mousemove(function (event) {
if ($(this).data('down') == true) {
this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
}
}).mousewheel(function (event, delta) {
this.scrollLeft -= (delta * 30);
}).css({
'overflow' : 'hidden',
'cursor' : '-moz-grab'
});
});
Run Code Online (Sandbox Code Playgroud)
有人可以给我指点吗?谢谢!
我试图修改这个 jQuery 滑块解决方案:https : //stackoverflow.com/a/9864636/908491(使用第一个解决方案 - http://jsfiddle.net/sg3s/rs2QK/)。
这是我的 jsFiddle:http : //jsfiddle.net/markrummel/KHSSX/。
DIV 滑入工作正常,但滑出的跳出,而不是以与 DIV 滑入相同的速度平滑滑出。我已.hide()在 javascript 和overflow:hiddenCSS 中注释掉,以便我可以看到在哪里被滑出的 DIV 消失了。
这是我第一次使用.animate(),因此非常感谢您提供的任何帮助!
这是我的javascript:
$('.date-nav-prev').click(function () {
$('.date-nav-next').show();
var current = $('.visible-actions');
var prev = current.prev('.user-actions');
current.removeClass('visible-actions').animate({
left: current.width()
}, 500, function() {
//current.hide();
});
prev.addClass('visible-actions').show().css({
left: -(prev.width())
}).animate({
left: 0
}, 500);
});
$('.date-nav-next').click(function () {
var current = $('.visible-actions');
var next = current.next('.user-actions');
current.removeClass('visible-actions').animate({
left: -(current.width())
}, 500, function() …Run Code Online (Sandbox Code Playgroud)