相关疑难解决方法(0)

滚动DIV元素时如何防止页面滚动?

我已经审查并测试了各种功能,以防止身体在div内部滚动,并结合了应该起作用的功能.

$('.scrollable').mouseenter(function() {
    $('body').bind('mousewheel DOMMouseScroll', function() {
        return false;
    });
    $(this).bind('mousewheel DOMMouseScroll', function() {
        return true;
    });
});
$('.scrollable').mouseleave(function() {
    $('body').bind('mousewheel DOMMouseScroll', function() {
        return true;
    });
});
Run Code Online (Sandbox Code Playgroud)
  • 这是停止所有滚动,因为我想在容器内仍然可以滚动
  • 鼠标离开时也不会停用此功能

这样做有什么想法或更好的方法吗?

jquery mousewheel

90
推荐指数
4
解决办法
11万
查看次数

如何区分手动滚动(通过鼠标滚轮/滚动条)与Javascript/jQuery滚动?

更新:

这是一个证明问题的jsbin示例.

更新2:
这是固定版本归功于fudgey.


基本上,我有以下javascript将窗口滚动到页面上的锚点:

 // get anchors with href's that start with "#"
 $("a[href^=#]").live("click", function(){
     var target = $($(this).attr("href"));
     // if the target exists: scroll to it...
     if(target[0]){
         // If the page isn't long enough to scroll to the target's position
         // we want to scroll as much as we can. This part prevents a sudden 
         // stop when window.scrollTop reaches its maximum.
         var y = Math.min(target.offset().top, $(document).height() - $(window).height());
         // also, don't …
Run Code Online (Sandbox Code Playgroud)

javascript jquery scroll scrollbar mousewheel

25
推荐指数
1
解决办法
1万
查看次数

没有滚动或跳转的HTML锚链接

我有各种链接,都有唯一的id是"伪锚".我希望它们影响url哈希值,并且点击魔法全部由一些mootools代码处理.但是,当我点击链接时,它们会自动滚动(或者在一个案例中滚动到顶部).我不想在任何地方滚动,但也需要我的javascript执行并在url更新中获得哈希值.

模拟的示例代码:

<a href="#button1" id="button1">button 1</a>
<a href="#button2" id="button2">button 2</a>
<a href="#" id="reset">Home</a>
Run Code Online (Sandbox Code Playgroud)

因此,如果您点击"按钮1"链接,则网址可以是http://example.com/foo.php#button1

有没有人对此有任何想法?简单地使用一些javascript返回void会导致滚动,但也会杀死我的javascript(虽然我可以使用onclick来解决这个问题)但更重要的是,可以防止url中的哈希值发生变化.

html javascript anchor xhtml scroll

24
推荐指数
4
解决办法
5万
查看次数

在没有移动页面的情况下在div中滚动

我有一个<div id="innerContent">overflow-y:scroll;.innerContent中锚点的链接位于父页面上,而不是在父页面上div.

到目前为止,我已尝试使用anchors和scrollto来尝试在内容中滚动.它们都完成滚动,但innerContent的高度大于浏览器窗口,因此当单击链接时,整个父页面也会滚动到锚点.

有没有办法用javascript执行此操作,而无需移动父页面?我无法控制div的高度 - 这是别人的设计.

这很接近......但这里没有答案. 如何在不滚动整个页面的情况下自动滚动内联div?

谢谢!

html javascript anchor scroll

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

javascript ×3

scroll ×3

anchor ×2

html ×2

jquery ×2

mousewheel ×2

scrollbar ×1

xhtml ×1