我想display:none如果用户将我的横幅悬停500ms,但以下JQuery代码无效.哪里出错?
$('.banner').hover(function() {
setTimeout(function(){
$(this).css('display','none');
}, 500);
});
Run Code Online (Sandbox Code Playgroud)
你不能$(this)在匿名函数中传递这样的东西.将其设置为变量
$('.banner').hover(function() {
var banner = $(this);
setTimeout(function() {
banner.css('display', 'none');
}, 500);
});
Run Code Online (Sandbox Code Playgroud)