所以,我在div中得到了一些数据.它按日期分成几块.它使用jQuery和mousewheel插件水平滚动.
当div达到它的终点(最左边,最右边)时,我需要发射一个事件.我认为通过检测在mousewheel插件中获取的数据,可以通过当前实现的方式来计算何时无法进一步滚动.我只需要朝着正确的方向轻推.这是为我进行水平滚动的代码:
$(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'
});
});
任何人都可以给我一些方向吗?谢谢!
解决方法
嘿,我已经为你准备了一个实施页面.您可以看到如何使用jQuery检测滚动区域的结尾.
对于整个文档,您必须在javascript中检测.scrollTop是否已等于.scrollHeight.使用jQuery,它将检测:
if ( $(document).scrollTop() == ( $(document).height() - $(window).height() ) {
// Do something here ...
}
宽度也是如此.看看div here的例子.