我有以下jQuery代码 -
$('div#mid_number_of_mail').mouseover(function () {
setTimeout(function () {
$('div.element_popup' ,this).stop().animate({
opacity : '1'
}, 250, 'linear', function() { });
}, 5000);
});
Run Code Online (Sandbox Code Playgroud)
但我不知道为什么它不能正常工作.有人可以帮我这个代码吗?
提前致谢!
因为this是window没有用给定ID的DIV.
this是基于如何调用函数的上下文敏感.
由于函数是通过调用的setTimout,因此它没有对象上下文,因此使用默认对象:window.
您想要this鼠标悬停功能,因此您需要将其副本保存在不同的变量中.
$('div#mid_number_of_mail').mouseover(function () {
var that = this; // Take the this from this context and keep it for other functions
setTimeout(function () {
$('div.element_popup', that).stop().animate({
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1080 次 |
| 最近记录: |