jQuery hover not triggered when element is programatically moved under the mouse

后端 未结 4 628
星月不相逢
星月不相逢 2021-01-02 22:16

I have an image with a hover effect (higher opacity when mouse is over it). It works as desired when the mouse moves in and out.

However, the image itself is moving

4条回答
  •  梦谈多话
    2021-01-02 22:51

    In addition to wajiw's and ryan's answers, you should trigger the mouseenter and mouseleave events as you detect that the mouse is over/not over the image, so that whatever code you bound to .hover() is still executed:

    $(".my-image").trigger("mouseenter");
    $(".my-image").trigger("mouseleave");
    

提交回复
热议问题