jquery - iOS touchmove 事件 - 改变 backgroundPosition 不流畅

标签 jquery ios parallax touchmove

我正在尝试创建简单的视差效果来改变背景位置,但在 iOS Safari 中移动不流畅。背景仅在我松开触摸屏时改变其位置,但在我滚动它时不会。

Javascript:

   $(window).bind('touchmove',function(e){  
        var scrolled = $(window).scrollTop();
        $('#home').css('backgroundPosition', 'center ' + (0-(scrolled*2)) +'px');
    });

它实际上不仅发生在更改 backgroundPosition 上,而且发生在 top 的 div 元素上:

$('#home').css('top', (scrolled*2) +'px');

但同时 margin-top 工作正常,移动流畅。

我做错了什么,我怎样才能让它像鼠标滚轮事件一样在 iOS 上工作?

最佳答案

iOS 浏览器会在滚动或手势发生时卡住 DOM 操作。这无法修复,因为这是浏览器的问题。来自 jQuery Mobile ,它说:

Note that iOS devices freeze DOM manipulation during scroll, queuing them to apply when the scroll finishes.

关于jquery - iOS touchmove 事件 - 改变 backgroundPosition 不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15596888/

相关文章:

ios - 未从文件中检索内容

ios - 如何在 Swift 中枚举 ALAssetsGroup

javascript - 一页网站的滚动效果

ios - Stellar Parallax 可在桌面上运行,在移动设备上运行静态图像

javascript - IE 中的视差滚动动画断断续续,但在 Chrome 和 Firefox 中却很流畅。我的代码或 IE 有问题?

javascript - jQuery .click 事件在页面加载时运行

javascript - jquery mobile 链接点击两次页面消失

ios - 如何向大量iPhone发送少量数据

asp.net - 如何使用jquery调用服务器端函数而不刷新页面?

javascript - 使用 Jquery 将 ajax 响应保存到数组