+ 2

How to make a function run while the button is HOLDED?

I want to run a function when the users hold their finger on the button...

19th Oct 2018, 8:16 AM
Jingga Sona
Jingga Sona - avatar
5 ответов
+ 6
/* You need to use ontouchstart and ontouchend events (or, for desktop, onmousedown and onmouseup). Do it like this: */ var start; var end; var elapsed; button.ontouchstart = function() { start = (new Date).getTime(); // Get the current time, in milliseconds }; button.ontouchend = function() { end = (new Date).getTime(); // Same here elapsed = (end - start) / 1000; // Calculate the number of seconds console.log(elapsed + " seconds"); };
19th Oct 2018, 8:25 AM
Rowsej
Rowsej - avatar
+ 3
Jingga Sona no worries again! I just thought of this now. And, you can also attach the function to any element (img, div, etc.). P.S. Is it your 3:30 now?
19th Oct 2018, 8:29 AM
Rowsej
Rowsej - avatar
+ 1
Rowsej Thank You!!!👍🙏😊 You are my best supporters😊
19th Oct 2018, 8:27 AM
Jingga Sona
Jingga Sona - avatar
+ 1
yes... this is 3:35pm here Rowsej
19th Oct 2018, 8:32 AM
Jingga Sona
Jingga Sona - avatar
0
just google it...
19th Oct 2018, 9:50 AM
ajay raja
ajay raja - avatar