How to stop toggle event from being fired multiple times on mouseenter/mouseleave?

前端 未结 3 1632
说谎
说谎 2021-01-01 03:51

I\'m using jQuery to toggle the visibility of a

using the jQuery toggle method. The toggle is fired on the mouseenter and mouseleave event, thus cre
3条回答
  •  青春惊慌失措
    2021-01-01 04:16

    Aside from the correct answer by Cletus, i'd like to point out that using mouseenter and mouseleave events is not wrong. The trick only resides into the stop() method, in fact we could still do:

    $("div.someclass").on("mouseenter", function() {
      $("...").stop().fadeIn("slow");
    });
    $("div.someclass").on("mouseleave", function() {
      $("...").stop().fadeOut("slow");
    });    
    

    Here is a jsFiddle example :)

提交回复
热议问题