Jquery 悬停问题淡入/淡出 - 停止闪烁!
我正在使用此脚本在将鼠标悬停在另一个脚本上时淡入图标。
我还想在顶部图像完成淡入后隐藏上一个图像。
我遇到的问题是,当您将鼠标悬停在其上时,它似乎在消失之前闪烁。我需要停止眨眼!
下面是我的 HTML 和 jQuery 代码。我试图使这段代码具有一定的通用性。
.link-container {
position: relative;
cursor: pointer;
float: left;
}
.title-hover {
background-position: 0 -106px;
width: 320px;
height: 33px;
margin: -32px 0 0 56px;
display: none;
z-index: 2;
}
.title {
background-position: 0 -63px;
width: 320px;
height: 33px;
margin: -32px 0 0 56px;
}
<div class="link-container">
<div class="main-tile hover-init title"></div>
<div class="main-tile title-hover"></div>
</div>
$(function () {
$(".link-container").hover(function () {
$(".hover-init", this).next().stop(true, true).fadeIn(400);
$(".hover-init", this).hide();
}, function () {
$(".hover-init", this).next().stop(true, true).fadeOut(400);
$(".hover-init", this).show();
});
});
I'm using this script to fade in icons over another when hovered over.
I also want to hide the previous image once the top image is finished fading in.
The problem I am running into is that when you hover over it seems to blink before it fades. I need the blinking to stop!
Below is my HTML and jQuery code. I tried to make this code somewhat universal.
.link-container {
position: relative;
cursor: pointer;
float: left;
}
.title-hover {
background-position: 0 -106px;
width: 320px;
height: 33px;
margin: -32px 0 0 56px;
display: none;
z-index: 2;
}
.title {
background-position: 0 -63px;
width: 320px;
height: 33px;
margin: -32px 0 0 56px;
}
<div class="link-container">
<div class="main-tile hover-init title"></div>
<div class="main-tile title-hover"></div>
</div>
$(function () {
$(".link-container").hover(function () {
$(".hover-init", this).next().stop(true, true).fadeIn(400);
$(".hover-init", this).hide();
}, function () {
$(".hover-init", this).next().stop(true, true).fadeOut(400);
$(".hover-init", this).show();
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想在淡入结束后开始淡出,对吗?然后将其设为 fadeIn 函数的回调:
编辑:
现在我看到了您想要实现的效果,我什至不知道为什么要淡出第一个 div。
http://jsfiddle.net/ARyjq/3/ 这样做
You want to start the fadeOut AFTER the fadeIn finishes, right ? Then make it a callback of the fadeIn function :
EDIT :
now that I see the effect you want to achieve I don't even know why you want to fadeOut the first div.
http://jsfiddle.net/ARyjq/3/ do that
问题是,当标题弹出时,悬停从一个 div 切换到另一个 div。
因此,您需要嗅探您所处的 div 类型并改变响应。
按照您的要求执行的代码如下所示:
在 jsFiddle 上查看它的实际应用。
The problem is that hover switches from one div to another as the title pops up.
So, you need to sniff what kind of div you are in and vary the response.
Code that does as you ask looks like this:
See it in action at jsFiddle.