JQuery 悬停效果淡入淡出 - 有帮助吗?
我正在尝试使用 JQuery 实现悬停淡出效果。目前我有一个带有“hov”类的元素受到攻击,如果没有javascript,CSS将简单地改变它在:hover上的颜色。使用 JQuery。
这个想法是在元素滚动时克隆它并将其直接放置在前面,剥离它的“hov”类,因此它只是静态的。然后我将其淡出,以创建过渡效果。
不过,我遇到了麻烦,在我从克隆中删除“hov”类后,它仍然表现得好像它仍然存在一样。我可以将鼠标悬停在克隆上,即使它不应该能够通过 hov 定位。有什么想法/技巧吗?
<a href="#" class="hov rounded-50 action-button">Fade Me Out< /a>
$(".hov").mouseover(function() {
// Clone the current element, remove the "hov" class so it won't trigger same behavior
// finally layer it infront of current element
var $overlay = $(this).clone(true).removeClass("hov").insertAfter($(this));
// Push it to the side just for testing purposes - fade it out
$overlay.css({left:'300px'}).fadeOut({duration:500, ease:'easeOutQuad'});
});
I'm trying to achieve a fade-on-hover effect with JQuery. Currently I have an element with a "hov" class attacked to it, without javascript the css will simply change it's color on :hover. With JQuery.
The idea is to clone the element as it's rolled over and place it directly infront, stripping it of the "hov" class so it's just static. Then I fade it out so it create the transition effect.
I'm having trouble though, after I strip the "hov" class from the clone, it KEEPS acting as though its still there. I can mouse over the clone even though it shouldn't be able to be targeted through hov. Any ideas / tips?
<a href="#" class="hov rounded-50 action-button">Fade Me Out< /a>
$(".hov").mouseover(function() {
// Clone the current element, remove the "hov" class so it won't trigger same behavior
// finally layer it infront of current element
var $overlay = $(this).clone(true).removeClass("hov").insertAfter($(this));
// Push it to the side just for testing purposes - fade it out
$overlay.css({left:'300px'}).fadeOut({duration:500, ease:'easeOutQuad'});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需克隆元素,只需淡出原始元素:
您还可以使用悬停功能:
如果您只想让它部分淡出,您可以为不透明度属性设置动画:
如果您只想让它脉冲,则返回正常不透明度:
最后,如果您愿意放弃对旧版浏览器的支持,您可以使用 css 来完成这一切:
No need to clone the element, just fade the original element:
You can also use the hover function:
If you just want it to partially fade, you can animate the opacity property:
If you just want it to pulse, then return to normal opacity:
Finally, if your willing to forgo support of older browsers, you can do it all with css: