Holla ,
this is the javascript im using
var timeoutID;
function setup() {
document.getElementById("demo").addEventListener("mousedown", resetTimer);
startTimer();
}
setup();
function startTimer() {
timeoutID = window.setTimeout(goInactive, 1000);
}
function resetTimer() {
window.clearTimeout(timeoutID);
goActive();
}
function goInactive() {
document.getElementById("demo").style.opacity = 0;
document.getElementById("demo").style.transition = "1s";
}
function goActive() {
document.getElementById("demo").style.opacity = 1;
document.getElementById("demo").style.transition = "1s";
startTimer();
}
everything is working fine , except i want it to go active only by left mouse button ( now right click left click and middle click are doing the job )
So many thanks in advance AliYous
You have to detect the left mouse button press by checking the event
object (Detect left mouse button press).
evt = evt || window.event;
if ("buttons" in evt) {
return evt.buttons == 1;
}
And then if it's left mouse (1
), proceed to do your job in resetTimer()
function. Final code will be:
function resetTimer(e) {
evt = e || window.event;
if ("buttons" in evt) {
if (evt.buttons == 1) {
window.clearTimeout(timeoutID);
goActive();
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With