$('.grow').hover(function(){
var _this = $(this); // 把$(this)对象赋给一个变量
trigger = setTimeout(function(){
_this.animate({height:'150px'},300);// (非常重要)jQuery的setTimeout中不能直接使用$(this)
},200); // 延迟时间0.2秒
}, function(){
clearTimeout(trigger); // 清除上面的延迟触发的事件
$(this).animate({height:'70px'},300);
});
setTimeout方法使用时需注意:
//以下两种方式都行:
setTimeout(function () { test(); }, 2000);
//或者
setTimeout('test()',2000);
function test(){
alert("aaaa");
}
//以下是错误示例
setTimeout(test(),2000);
//会马上执行,没有延迟效果