mercredi 15 juin 2016

Javascript clicked and not been clicked for 4 seconds

I have a question about my code. What I'm trying to do is if a certain button is clicked and it isn't clicked again within 4 seconds, a element will be showed and another element hide. But if it is clicked within 4 seconds, it stays the same and so on. I think I should use SetInterval() and ClearInterval(). Currently I have two other functions that do other thinks. Maybe I can my function there?

Hopefully I have made it clear.

Current javascript code:

var clicks = 0;
function clicks5times() {
  clicks = clicks+1;
  if(clicks == 6){
    document.getElementById('scherm3').style.display = 'block';
     document.getElementById('scherm2.2').style.display = 'none'; 
  }
}           

var clicked = false;
setInterval(function(){
    if (!clicked) {
    document.getElementById("scherm4").style.visibility = "visible";
    document.getElementById("scherm2.2").style.visibility = "hidden";
  }
},13000);

document.getElementById("buttontimer").addEventListener("click", function(){
    clicked = true;
});

Aucun commentaire:

Enregistrer un commentaire