0

I've got several functions set to different timeouts that are called on any button click. For some reason, all of them don't execute on the first click.

www.bobbysimmonspro.com

Also, as a sidebar, i'll gladly hear any opinions about the way i'm approaching this, plugins to simplify, and general tips or helpful links on the process of debugging something like this.

$( document ).ready(function() {

var panelClassName = 'show-front';

$("#cube").toggleClass("backFace");


setTimeout(function(){ 
    $("#show-buttons").on('click', '*', function() {
        $("#cube").removeClass("backFace");
        $("#cube").animate({opacity: .3});
        $("#cube").removeClass( panelClassName );   
    });
}, 500);

setTimeout(function(){ 
    $("#show-buttons").on('click', '*', function() {
            panelClassName = event.target.className;
        });     
}, 1000);


setTimeout(function(){ 
    $("#show-buttons").on('click', '*', function() {        
        $("#cube").addClass( panelClassName );
        $("#cube").animate({opacity: 1});   
    });     
}, 3000);

setTimeout(function(){ 
    $("#show-buttons").on('click', '*', function() {
        $("#cube").addClass("backFace");
    });
}, 3500);


});
RedBeardPro
  • 89
  • 1
  • 10
  • 1
    That's just all wrong, There's really no reason to put event handlers inside timeouts, those timeouts have nothing to do with the clicks, they just delay adding the event handler? Also, delegating to `*` makes very little sense ? – adeneo Oct 10 '15 at 14:58

1 Answers1

2

In your code you set the event handler with the setTimeout method. I guess what you really want to do is to trigger some action with a delay after the user clicks on a button. So maybe something like this:

$("#show-buttons").on('click', '*', function() {
    setTimeout(function(){
        $("#cube").removeClass("backFace");
        $("#cube").animate({opacity: .3});
       $("#cube").removeClass( panelClassName );   
    }, 500);
});
PatrickD
  • 1,136
  • 5
  • 7
  • Thank you, answer with Adeneo's comment put me on the right track. Now i've got a different problem, but i believe you've answered this question. – RedBeardPro Oct 10 '15 at 17:28