mouseenter, leave 這種怎麼簡寫啊?

$(".help_cover").mouseenter(function(event) {
  $(".layout_help_cover").fadeIn();
});
$(".help_cover").mouseleave(function(event) {
  $(".layout_help_cover").fadeOut();
});

請問這種代碼能怎麼簡寫?我想到是這樣了,沒有別的方式,有大神知道還能再簡寫嗎?

阅读 1.8k
2 个回答
$(".help_cover")
.mouseenter(function(event) {
  $(".layout_help_cover").fadeIn();
})
.mouseleave(function(event) {
  $(".layout_help_cover").fadeOut();
});

略微简化一点点

var $aniCover = $('.layout_help_cover');
$('.help_cover').on({
    mouseenter: function() {
        $aniCover.fadeIn();
    },
    mouseleave: function() {
        $aniCover.fadeOut();
    },
});

个人觉得jQ的事件简写其实很鸡肋。。。(当然放在文档里提醒你有什么事件可以用这点还是有一定现实意义的。)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题