+ 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...
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");
};
+ 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?
+ 1
Rowsej Thank You!!!👍🙏😊 You are my best supporters😊
+ 1
yes... this is 3:35pm here
Rowsej
0
just google it...