How to monitor the sliding of the mobile phone screen and calculate the scrolling distance from the top?
$('body').bind('touchmove', function(e) {
var winHeight = $(window).scrollTop();
console.log(winHeight);
});
What I write like this is always 0? Monitoring scroll has no effect! Ask God
習慣沉默2017-05-19 10:13:07
$('body').on("touchstart",function(ev){
var winHeight = $(window).scrollTop();
$('body').on("touchmove",function(ev){
console.log(winHeight);
})
});
Try writing it like this
仅有的幸福2017-05-19 10:13:07
window.addEventListener('scroll',function(){
console.log(window.scrollY)
})
大家讲道理2017-05-19 10:13:07
let oB = document.getElementById('objEl')
let oBh = oB.offsetTop
oB.addEventListener('touchstart', function (e) {
startX = e.touches[0].pageX
startY = e.touches[0].pageY
})
oB.addEventListener('touchmove', function (e) {
let endX = e.changedTouches[0].pageX
let endY = e.changedTouches[0].pageY
}, false)
oB.addEventListener('touchend', function () {
// ...
})