// if the box is outside the window, move it to the end
function checkEdge() {
var windowsLeftEdge = $('#window').position().left;
$('.box').each( function(i, box) {
// right edge of the sliding box
var boxRightEdge = $(box).position().left + $(box).width();
// position of last box + width + 10px
var newPosition = getNewPosition();
if ( parseFloat(boxRightEdge) < parseFloat(windowsLeftEdge) ) {
$(box).css('left', newPosition);
$(box).remove().appendTo('#window');
first = $('.box:first').attr('class');
}
});
}? //Uncaught SyntaxError: Unexpected token ILLEGAL Occurs Here
// arrange the boxes to be aligned …Run Code Online (Sandbox Code Playgroud) 我在页面中有一个垂直滚动的div也可以垂直滚动.
当使用鼠标滚轮滚动子div并到达滚动条的顶部或底部时,页面(正文)开始滚动.当鼠标在子div上时,我希望页面(正文)滚动被锁定.
这个SO帖子(向下滚动到所选答案)很好地证明了这个问题.
这个SO问题与我的问题基本相同,但选定的答案会导致我的页面内容在滚动条消失并重新出现时明显地水平移动.
我认为可能有一个利用event.stopPropagation()的解决方案,但无法获得任何工作.在ActionScript中,这种事情可以通过在子事件上放置一个鼠标轮处理程序来解决,该子事件在事件到达body元素之前调用stopPropagation().由于JS和AS都是ECMAScript语言,我认为这个概念可能会翻译,但它似乎没有用.
是否有解决方案可以防止我的页面内容移动?最有可能使用stopPropagation而不是CSS修复?JQuery的答案和纯JS一样受欢迎.
我使用twitter bootstrap 3.我添加了固定顶部导航栏.我在导航栏上有下拉按钮.当用户点击按钮时,会打开一个下拉菜单.对于桌面用户来说没问题.但对于移动用户,当用户向下滚动下拉链接时,后面的页面也会滚动.
用户滚动下拉链接时是否可以禁用后台页面滚动?
小提琴:http://jsfiddle.net/mavent/2g5Uc/1/
当用户触摸下拉部分并触摸绿色箭头时,背景页面会像此屏幕截图中的红色箭头一样滚动:

<nav class="navbar navbar-inverse navbar-fixed-top visible-xs" role="navigation">
<div class="navbar-header" style="text-align:center;">
.......
</div>
Run Code Online (Sandbox Code Playgroud)
编辑:这不起作用.这将停止所有页面滚动.
$('#my_navbar_div').bind('touchmove', function(event)
{
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
这不起作用.没有改变任何行为:
$('#my_navbar_div').hover(function() {
$(document).bind('touchstart touchmove',function(){
$("body").css("overflow","hidden");
});
}, function() {
$(document).unbind('touchstart touchmove');
});
Run Code Online (Sandbox Code Playgroud) 我试图捕捉鼠标滚轮是否被触发以及它是否向上或向下滚动而没有实际滚动页面(正文有溢出:隐藏).
任何想法是如何使用jQuery或纯JavaScript实现这一点?
$(window).scroll(function(){
if( /* scroll up */){ }
else { /* scroll down */ }
});
Run Code Online (Sandbox Code Playgroud)