我在使用 setTimeout() 时遇到问题。我希望在鼠标移出状态下,子菜单在一段时间间隔(500 毫秒)后向上滑动。但 setTimeout() 不起作用。
就像这个链接:http://jsfiddle.net/felipepalazzo/Xyhvn/2/
代码:
(function($){
$.fn.showMenu = function(options){
var settings = $.extend({
height : '40px',
speed : '500',
heightx : '20px'
}, options || {});
return this.each(function(){
var elem = $(this);
var menu_timer;
elem.hover(function(){
$(this).stop().animate({'height' : settings.height}, settings.speed);
}, function(){
//setTimeout(function(){
$(this).stop().animate({'height' : settings.heightx}, settings.speed);
//},500);
});
});
};
})(jQuery);
最佳答案
这超出了范围。
var that = this;
setTimeout(function(){
$(that).stop().animate({'height' : settings.heightx}, settings.speed);
},500);
关于javascript - JQuery 动画中的 setTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10840106/