悬停设置超时不起作用

use*_*989 2 javascript jquery

我想display:none如果用户将我的横幅悬停500ms,但以下JQuery代码无效.哪里出错?

$('.banner').hover(function() {

      setTimeout(function(){

      $(this).css('display','none');

    }, 500);
}); 
Run Code Online (Sandbox Code Playgroud)

Ste*_*ins 6

你不能$(this)在匿名函数中传递这样的东西.将其设置为变量

$('.banner').hover(function() {

    var banner = $(this);

    setTimeout(function() {

        banner.css('display', 'none');

    }, 500);


});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/fkjn6/