Disable :hover on click

后端 未结 5 1334
醉梦人生
醉梦人生 2021-01-31 20:18

I have a div that has hover:

.div {
  // css
}
.div:hover {
  // css
}

But I want to disable the hover when you click on the

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 20:30

    Try like this:

    $('#myid').on({
        mouseover: function(){
            $(this).css({background: '#F94'});
        },
         mouseleave: function(){
            $(this).css({background: '#DDD'});
        },
        click: function(){
            $(this).off('mouseleave');
        }
    });
    

    JSFIDDLE DEMO

提交回复
热议问题