jmo*_*rdt 4 jquery scroll mousewheel
所以,我在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检测滚动区域的结尾.
对于整个文档,您必须在javascript中检测是否.scrollTop已经等于.scrollHeight.使用jQuery,它将检测:
if ( $(document).scrollTop() == ( $(document).height() - $(window).height() ) {
// Do something here ...
}
Run Code Online (Sandbox Code Playgroud)
宽度也是如此.看看div 这里的例子.
这是您想要的代码。事实证明,它适用于 IE、Safari、Chrome、Firefox 等。
这是 HTML 部分。
<div id="slide-wrap" style="width:1000px; height:200px; overflow:hidden; padding:0 auto;">
<div id="inner-wrap" style="float:left;">
<!-- 'Put Inline contains here like below.' -->
<div class='containBox' style="width:250px; height:100%; float:left; display:inline-block;"></div>
<!-- ... -->
<div class='containBox' style="width:250px; height:100%; float:left; display:inline-block;"></div>
<!-- 'Put Inline contains here like above.' -->
</div>
<div style="display: block; width:40px; height:60px; position: absolute; margin-left:0px; margin-top:40px">
<img id='scroll_L_Arrow' src='../assets/img/l-arrow.png' onclick="scrollThumb('Go_L')"/>
</div>
<div style="display: block; width:40px; height:60px; position: absolute; margin-left:960px; margin-top:40px">
<img id='scroll_R_Arrow' src='../assets/img/r-arrow.png' onclick="scrollThumb('Go_R')"/>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是 JavaScript 函数中的 jQuery 部分。
function scrollArrowShow() {
var maxScroll = ($('#inner-wrap').width() - $('#slide-wrap').scrollLeft()) - $('#slide-wrap').width();
if ( 0 == $('#slide-wrap').scrollLeft()) {
$('#scroll_L_Arrow').css({visibility: 'hidden'});
}else{
$('#scroll_L_Arrow').css({visibility: 'visible'});
}
if ( 0 == maxScroll) {
$('#scroll_R_Arrow').css({visibility: 'hidden'});
}else{
$('#scroll_R_Arrow').css({visibility: 'visible'});
}
}
function scrollThumb(direction) {
if (direction=='Go_L') {
$('#slide-wrap').animate({
scrollLeft: "-=" + 250 + "px"
}, function(){
// createCookie('scrollPos', $('#slide-wrap').scrollLeft());
scrollArrowShow();
});
}else
if (direction=='Go_R') {
$('#slide-wrap').animate({
scrollLeft: "+=" + 250 + "px"
}, function(){
// createCookie('scrollPos', $('#slide-wrap').scrollLeft());
scrollArrowShow();
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24179 次 |
| 最近记录: |