定时器重置功能不起作用!
大家好!
我一直在尝试为我最新的 jQuery 插件创建一个简单的示例代码,但它似乎根本不起作用!谁能告诉我哪里出了问题?或者任何人都可以为我提供一个新功能来做到这一点。所以我的问题是,当我将鼠标悬停在一个名为 trigger
的元素上时,另一个名为 eg
的元素应该 fadeIn();
但如果用户取出在类 eg
的元素淡入之前,鼠标不应再淡入,但这根本不起作用。我不知道出了什么问题?请帮帮我。 (下面是我的问题 HTML nad Jquery 代码!)
HTML 代码
<div class="trigger">MouseOverMe</div>
<div class="eg">See Me!</div>
JQUERY 代码
function timereset(a)
{
var elem = $('.'+a);
if(elem.data('delay')) { clearTimeout(elem.data('delay')); }
}
$(document).ready(function () {
$('div.eg').hide();
$('div.trigger').mouseover(function () {
$('div.eg').delay(1000).fadeIn();
});
$('div.trigger').mouseout(function () {
timereset('eg');
$('div.eg').fadeOut();
});
});
提前致谢
Hello Guys!
I have been trying to create a simple sample code for my newest jQuery Plugin, but it doesn't seems to be working at all! Can anyone tell where I'm going wrong?, or can anyone provide me a new function to do it. So my problem is that when I mouse over an element classed trigger
an another element classed eg
should fadeIn();
but if the user takes out the mouse before the element classed eg
fades in it should not be fading in anymore, but this is not working at all. I don't not what is getting wrong? Please help me out. (Below is my Problem HTML nad Jquery Code!)
HTML CODE
<div class="trigger">MouseOverMe</div>
<div class="eg">See Me!</div>
JQUERY CODE
function timereset(a)
{
var elem = $('.'+a);
if(elem.data('delay')) { clearTimeout(elem.data('delay')); }
}
$(document).ready(function () {
$('div.eg').hide();
$('div.trigger').mouseover(function () {
$('div.eg').delay(1000).fadeIn();
});
$('div.trigger').mouseout(function () {
timereset('eg');
$('div.eg').fadeOut();
});
});
THANKS IN ADVANCE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不需要
timereset
东西,只需在对象上调用stop()
,之前的效果就会停止:http://api.jquery.com/stop/
根据新评论更新:
You don't need that
timereset
stuff, simply callstop()
on the object and the previous effect will stop:http://api.jquery.com/stop/
Update based on the new comment:
jQuery
小提琴: http://jsfiddle.net/UJBjg/1
jQuery
Fiddle: http://jsfiddle.net/UJBjg/1
另一种选择是清除排队的功能,例如:
请记住,如果淡出/淡入已经通过使用 stop 开始,则最终可能会出现半透明元素。
编辑
这是一个示例:http://jsfiddle.net/Qchqc/
Another option would be to clear the queued functions like:
Bear in mind if the fadeOut/In has already started by using stop you could end up with a semi-transparent element.
EDIT
Here's an example: http://jsfiddle.net/Qchqc/