Tell me why it works alone for the second time.



  • $(document).ready(function(){
    
        $('.run').click(function(){
          var $mgTop = $('.itmFirst').css('margin-top');
          if($mgTop<'100px'){ 
             $('.itmFirst').animate({marginTop:'+=30px'},1000,function(){});
          };
        });
    


  • Example of work http://jsfiddle.net/szpayf30/

    $('.run').click(function(){
      var mgTop = $('.itmFirst').css('margin-top').replace("px", "");
      if(mgTop<100){ 
         $('.itmFirst').animate({marginTop:'+=30px'},1000,function(){});
      };
    });
    

    The properties should be removed from the line. pxso there's only a number in the line. And then, if you compare the number, not the line.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2