search

Home  >  Q&A  >  body text

javascript - How to monitor the sliding of the mobile phone screen and the distance from the top of the sliding screen?

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

黄舟黄舟2786 days ago667

reply all(4)I'll reply

  • 某草草

    某草草2017-05-19 10:13:07

    $(window).scroll(function () {
      // 你的代码
    });

    reply
    0
  • 習慣沉默

    習慣沉默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

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-19 10:13:07

    window.addEventListener('scroll',function(){
      console.log(window.scrollY)
    })

    reply
    0
  • 大家讲道理

    大家讲道理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 () {
        // ...
      })

    reply
    0
  • Cancelreply