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
人生最曼妙的風(fēng)景,竟是內(nèi)心的淡定與從容!
$('body').on("touchstart",function(ev){
var winHeight = $(window).scrollTop();
$('body').on("touchmove",function(ev){
console.log(winHeight);
})
});
Try writing it like this
window.addEventListener('scroll',function(){
console.log(window.scrollY)
})
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 () {
// ...
})