javascript - How to monitor the sliding of the mobile phone screen and the distance from the top of the sliding screen?
黄舟
黄舟 2017-05-19 10:11:07
0
4
666

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

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
某草草
$(window).scroll(function () {
  // 你的代码
});
習慣沉默
$('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 () {
    // ...
  })
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template