Get the $(document).scrollTop() with touchmove in ios

问题内容:

I want to get the value of $(document).scrollTop() on my iOS device using touchmove. Strangely, it works on Windows, MacOS, and Android, but it does not work on iOS.

 $(document).bind({'touchmove': function(e){
   console.log($(document).scrollTop()); a = true; console.log(a);
 }});

$(document).scrollTop() will continue to return the value 0.

window.requestAnimationFrame() also fails.

Anyway, I want to update the console.log($(document).scrollTop()) value.

问题评论:

答案:

答案1:

.scrollTop would work on $(“body”) but not $(“html, body”)

The browser support

IE8, Firefox, Opera: $(“html”)
Chrome, Safari, Chrome (Mac): $(“body”)

if($.browser.safari)
    scrollElement = $("body")
else
    scrollElement = $("html,body")

scrollElement .animate( {scrollTop: 0}, 100 );

答案评论:

原文地址:

https://stackoverflow.com/questions/47733335/get-the-document-scrolltop-with-touchmove-in-ios

添加评论

友情链接:蝴蝶教程