Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Detect document scrolling on mobile without touch event

I am trying to achieve an effect on a site I'm working on, where as the user scrolls vertically, an element slides horizontally the relative amount (i.e. if the user scrolls down by 10% of the document height, the particular element will move to the left by 10% of its own width).

The issue I'm having is that I'm using the touchstart and touchend events to calculate how much the user has scrolled vertically. However, on mobile devices (e.g. iPhone), the document will continue to scroll for a short while after the user finishes swiping and stops touching the screen.

Is there an alternative way to detect the document scrolling on mobile devices that will include the distance scrolled after the touch event ends?

Thanks!

My code:

            var wave = $('.front-page__mobile-wave');
            var height = $(document).height();
            var width = wave.width();
            var oneWidth = width/100;
            var ts;

            $(document).bind('touchstart', function (e){
                ts = e.originalEvent.touches[0].clientY;
             });

            $('.front-page').bind('touchmove', function(e){
                var te = e.originalEvent.changedTouches[0].clientY;
                var scroll = $(window).scrollTop();
                var percentHeight = scroll / height * 100;
                var bgSlideForward = oneWidth * percentHeight;
                var bgSlideBack = -oneWidth * percentHeight;
                if(ts < te){
                    wave.css('left', bgSlideBack);
                } else if (ts > te){
                    wave.css('left', -bgSlideForward);
                }
            });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Resolution was to use the scroll event instead of touchstart and touchmove and use variables to keep track of the current vs previous scrollTop, i.e.:

            var wave = $('.front-page__mobile-wave');
            var height = $(document).height();
            var width = wave.width();
            var oneWidth = width/100;
            var lastScrollTop = 0;
            $(window).scroll(function(e){
                var scroll = $(window).scrollTop();
                var percentHeight = scroll / height * 100;
                var bgSlideForward = oneWidth * percentHeight;
                var bgSlideBack = -oneWidth * percentHeight;
                if(scroll > lastScrollTop){
                    wave.css('left', bgSlideBack);
                } else if (scroll < lastScrollTop){
                    wave.css('left', -bgSlideForward);
                }
                lastScrollTop = scroll;
            });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!