Trigger the css:hover event with js

前端 未结 2 426
旧时难觅i
旧时难觅i 2020-12-11 19:04

I have

and in css:

div.animate:hover{
//do stuff
}

But would also like to invoke this via javas

2条回答
  •  时光说笑
    2020-12-11 19:44

    Instead of doing it this way, I suggest you just add a class to the other tag. In jQuery it would be:

     $(window).load(function() {
        $('.trigger-animate').hover(function(){
            $('.animate').addClass('hover');
        });
    }
    

    I'd recommend using this method, because it handles both onMouseOver and onMouseOut (this way you can also remove the class when your mouse leaves $('.trigger-animate') if you so desired using this syntax:

    .hover( handlerIn(eventObject), handlerOut(eventObject) )
     checking out the documentation
    

提交回复
热议问题