jQuery活动滚动事件在移动(解决) [英] jQuery live scroll event on mobile (work around)

查看:118
本文介绍了jQuery活动滚动事件在移动(解决)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

年龄老问题:
当用户在移动网站或应用程序(网络视图)上滚动元素时,使滚动事件触发。

The age old problem: Getting the scroll event to fire while a user is scrolling on an element while on a mobile site or app(web view).

所有我正在寻找的都是访问正确的 scrollTop()值,当用户在移动设备上滚动我的页面,而不是在用户停止时获取

All I'm looking for is access to the correct scrollTop() value while a user is scrolling my page on a mobile device instead of getting it when the user stops.

我确定有一个解决方法,如果我是正确的,这个限制是由iOS设置的,并且在过去几年里已经讨论过了。

I'm sure there is a workaround somewhere, if I'm correct this limitation is set by iOS and there has been discussion over it for the past few years.

我已经尝试实施本机滚动模拟器,但没有一个似乎正在工作我想要的,老实说,如果我真正想要的是一个持久的

I've tried implementing native scroll emulators but none of them seem to be working how I want and to be honest it seems like overkill if all I really want is a persistent scrollTop() while a user is scrolling.

我正在考虑在touchStart上启动一个计数器,阻止它在touchStop上,但有些东西告诉我我在浪费我的时间。

I'm currently thinking about maybe starting a counter on touchStart and stopping it on touchStop but something tells me I'm wasting my time.

任何帮助的人?

推荐答案

Wi th jQuery:

With jQuery:

$('body').bind('touchmove', function(e) { 
    console.log($(this).scrollTop()); // Replace this with your code.
});

当用户滚动时,这应该会给你一个一致的scrollTop值流,但要小心即使用户只是将手指放在屏幕上也会起火。

This should give you a consistent stream of the scrollTop value when the user scrolls, but be careful as it's going to fire even while the user is just holding his finger on the screen.

请注意,如果您使用jQuery> = 1.7,首选绑定方法是
.on()而不是我在我的例子中使用的 .bind()方法。在这种情况下,我的例子将是

Note that if you're using jQuery >= 1.7 the preferred binding method is .on() instead of the .bind() method I've used in my example. In that case my example would be

$('body').on({
    'touchmove': function(e) { 
        console.log($(this).scrollTop()); // Replace this with your code.
    }
});

资料来源: https://github.com/dantipa/pull-to-refresh-js/blob/master/jquery.plugin.pullToRefresh.js

这篇关于jQuery活动滚动事件在移动(解决)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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