user964351
user964351

Reputation: 271

JQuery - How to fix mouseover and mouseleave auto loop a lot of times?

When I faster to mouseover and leave #go in a short time, it will auto loop a lot of times. How to fix it??

$("#go").mouseover(function(){
  $("#block").animate({ width: "900px" }, 300 );
});

$("#go").mouseleave(function(){                       
  $("#block").animate({ width: "0px" }, 300 );
});

Upvotes: 0

Views: 260

Answers (1)

Rafay
Rafay

Reputation: 31033

use stop()

$("#go").mouseover(function(){
  $("#block").stop(true,true).animate({ width: "900px" }, 300 );
});

$("#go").mouseleave(function(){                       
  $("#block").animate({ width: "0px" }, 300 );
});

Upvotes: 1

Related Questions