检测溢出中的滚动尝试:隐藏页面? [英] Detect scrolling attempts in overflow:hidden page?

查看:130
本文介绍了检测溢出中的滚动尝试:隐藏页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测用户正在尝试在我的页面上向上或向下滚动,但由于我不想允许实际滚动我设置了一个overflow:hidden body。代码如下所示:

I want to detect when the user is trying to scroll up or down on my page, but since I don't want to allow the actual scrolling I have set an overflow:hidden body. The code is something like this:

$('html,body').css('overflow','hidden');
$(window).scroll(function(event){
    console.log("scroll");
});

问题是,由于没有实际的滚动我无法启动的事件,溢出风格和以某种方式防止滚动,但我不知道如何做。

The problem is that since there is no actual scrolling I cannot fire the event, I have thought about removing the overflow style and somehow preventing scrolls but I cannot figure out how to do it.

无论如何有一种方法来修复滚动,同时检测滚动尝试?感谢

Anyway is there a way to fix the scrolling while detecting scrolling attempts? Thanks

推荐答案

尝试使用jQuery mousewheel https://github.com/brandonaaron/jquery-mousewheel 。您可以检测鼠标滚轮运动。另一个选项是不将溢出设置为隐藏,而是捕获滚动尝试并自己滚动。还有一堆JS滚动的库,我喜欢 http://manos.malihu .gr / jquery-custom-content-scroller /

Try using jQuery mousewheel https://github.com/brandonaaron/jquery-mousewheel. You can detect the mousewheel movement. The other option is to not set the overflow to hidden but instead catch the scroll attempt and scroll them yourself. There are also a bunch of libraries for JS scrolling, I like http://manos.malihu.gr/jquery-custom-content-scroller/.

这篇关于检测溢出中的滚动尝试:隐藏页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆