Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery detect user interaction

I have this code that scrolls the page automatically and stops the animation when the user interacts with the page. THis working properly on desktop devices but not on iphone. When the user try to scroll the page with his finger the animation doesn't stop until reach the bottom of the page. What can i do for this? Thanks!

$("html,body").stop().animate({scrollTop: $(document).height()}, 2000);

// Stop the animation if the user scrolls. Defaults on .stop() should be fine
$("body,html").bind("scroll mousedown DOMMouseScroll mousewheel keyup", function(e){
    $("html,body").stop();
});  
like image 469
George Avatar asked Jun 15 '13 09:06

George


People also ask

How can I detect with javascript jQuery if the user is currently active on the page?

Ifvisible. js is a crossbrowser lightweight solution that does just that. It can detect when the user switches to another tab and back to the current tab. It can also detect when the user goes idle and becomes active again.

How check user is active or not in Javascript?

Bellow is the function on how to check user if user is active or inactive using Javascript. On these events trigger, resetTime() function will trigger and time will be cleared. So if none of these event happen, then alertUser() function will be trigger. You can set any action in alertUser() method, that you want to do.

How do you find the change field input?

The change() is an inbuilt method in jQuery that is used to detect the change in value of input fields. This method works only on the “<input>, <textarea> and <select>” elements.


2 Answers

I add this in the bind area and it works "touchstart touchmove"

$("body,html").bind("touchstart touchmove scroll mousedown DOMMouseScroll mousewheel keyup", function(e){
    $("html,body").stop();
});  
like image 187
George Avatar answered Sep 24 '22 21:09

George


If you need only to detect it once, you can use

$("body,html").one("touchstart touchmove scroll mousemove mousedown DOMMouseScroll mousewheel keyup", function(e){
    console.log('Detected');
});
like image 33
Khachatur Avatar answered Sep 22 '22 21:09

Khachatur