Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm trying to make the click only work 4 times and then not work afterwards although I am unsure what I am doing incorrectly?

I'm trying to make the click only work 4 times and then o the opposite once that is finished although I am unsure what I am doing incorrectly?

 $(document).ready(function(){
   i=0;
   if(i<3){
     $('#nums').click(function(){
       $('#pic').stop().animate({top:'-=384px'},'300');
       i++;
     });        
   }else{
     $('#nums').click(function(){
       $('#pic').stop().animate({top:'+=384px'},'300'); 
     });
   }
});
like image 907
Delrog Avatar asked Jan 23 '26 02:01

Delrog


1 Answers

You should wrap the .click around the "if else". Something like this:

$(document).ready(function(){
    var i=0;
    $('#nums').click(function(){
    if(i<3){
        $('#pic').stop().animate({top:'-=384px'},'300');
    i++;
        }else{
        $('#pic').stop().animate({top:'+=384px'},'300');    
        }
    });
});
like image 184
Daniel I. Avatar answered Jan 25 '26 15:01

Daniel I.