Javascript 如何向这个JQuery事件添加延迟?
这是一个附加一些html的事件:Javascript 如何向这个JQuery事件添加延迟?,javascript,jquery,Javascript,Jquery,这是一个附加一些html的事件: $("#feed").live("mouseover", function(){ $("#main").append('<div class="help_div" id="feed_help"><p>Your feed shows you information on the users you follow, such as songs added, voting, commenting, following, an
$("#feed").live("mouseover", function(){
$("#main").append('<div class="help_div" id="feed_help"><p>Your feed shows you information on the users you follow, such as songs added, voting, commenting, following, and the showing of songs between users.</p></div><div class="arrow" id="feed_arrow"></div>');
});
我如何使鼠标移动到所选元素和追加html之间有2000毫秒的间隔?您将使用超时
$("#feed")
.live("mouseover", function() {
$(this).data("timeout", setTimeout(function() {
$("#main").append('<div class="help_div" id="feed_help"><p>Your feed shows you information on the users you follow, such as songs added, voting, commenting, following, and the showing of songs between users.</p></div><div class="arrow" id="feed_arrow"></div>');
}, 2000));
});
您将使用一个超时
$("#feed")
.live("mouseover", function() {
$(this).data("timeout", setTimeout(function() {
$("#main").append('<div class="help_div" id="feed_help"><p>Your feed shows you information on the users you follow, such as songs added, voting, commenting, following, and the showing of songs between users.</p></div><div class="arrow" id="feed_arrow"></div>');
}, 2000));
});
您也可以使用
这个方法是在jQuery1.4中添加的
使用此选项,您的代码将变成:
$("#feed").live("mouseover", function(){
$("#main").delay(2000).append('<div class="help_div" id="feed_help"><p>Your feed shows you information on the users you follow, such as songs added, voting, commenting, following, and the showing of songs between users.</p></div><div class="arrow" id="feed_arrow"></div>');
});
您也可以使用
这个方法是在jQuery1.4中添加的
使用此选项,您的代码将变成:
$("#feed").live("mouseover", function(){
$("#main").delay(2000).append('<div class="help_div" id="feed_help"><p>Your feed shows you information on the users you follow, such as songs added, voting, commenting, following, and the showing of songs between users.</p></div><div class="arrow" id="feed_arrow"></div>');
});
@Alnitak,你能解释一下,为什么使用.data来存储计时器句柄是件好事吗?@Starx因为它允许每个元素都存储自己的计时器,而不必跟踪整个JS变量。@Alnitak,你能解释一下,为什么使用.data来存储计时器句柄,是一件好事吗?@Starx因为它允许每个元素都存储自己的计时器,而不必跟踪整个JS变量负载。