jQuery switchClass
是否可以撤消 switchClass
转换?
我希望一个元素在您将鼠标悬停在其上时慢慢获得类 A
,并在鼠标移开后再次慢慢失去它。但是,该函数似乎有问题,并且调用 .stop(0,1)
似乎没有帮助。事实上,它似乎打破了它。
我有一个实例这里。是的,这是一个 404 页面,但这并不重要。导航应该慢慢地获得或失去一个等级,但它只是跳跃。该脚本可以在此处找到。
这样的转变可能吗?
编辑:
这是我正在使用的代码:
$('#navbar li:not(.current) a').hover(function() {
$(this).parent()
.stop(1,0)
.addClass('current', 1000);
}, function () {
$(this).parent()
.stop(1,0)
.removeClass('current', 1000);
});
是否可能是因为更改 li 的类不会导致其子级的样式被转换?
EDIT2:
是的,这“修复”了它。现在可以观察到真正的错误的全部荣耀(冻结在中间状态)。
Is it possible to undo a switchClass
transition?
I'd like an element to slowly obtain class A
as you hover over it, and slowly lose it again once the mouse has moved away. However, the function appears to be glitchy, and calling .stop(0,1)
doesn't seem to help. In fact, it seems to break it.
I have a live example here. Yes, it's a 404 page, but that's not important. The navigation should be slowly gaining or losing a class, but it just jumps. The script can be found here.
Is such a transition possible?
EDIT:
Here's the code I'm using:
$('#navbar li:not(.current) a').hover(function() {
$(this).parent()
.stop(1,0)
.addClass('current', 1000);
}, function () {
$(this).parent()
.stop(1,0)
.removeClass('current', 1000);
});
Is it perhaps because changing the class of the li
doesn't result in the style of its children being transitioned?
EDIT2:
Yup, that 'fixed' it. The true bug can now be observed in all its glory (getting frozen in an intermediate state).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
慢慢考级是没有意义的。一个元素要么有一个特定的类,要么没有,CSS 没有提供任何方法来指示类中的某种“部分包含”。
编辑 — @patrick 指出 jQuery UI 确实支持这一点,至少在某种程度上是这样。如果您安装了效果器,类操作函数将采用持续时间参数。
It doesn't make sense to slowly obtain a class. An element either has a particular class or it doesn't, and CSS provides no way to indicate some sort of "partial inclusion" in a class.
edit — @patrick points out that jQuery UI does indeed support that, at least to some extent. The class-manipulating functions take a duration argument if you install the effects stuff.
这是我最接近使其工作的方法:
示例: http://jsfiddle .net/TUrvP/
可能有些矫枉过正,你也许可以使用
:animated
选择器,尽管我一开始遇到了麻烦。可能不值得付出努力...
HTML
CSS
jQuery
This is the closest I've come to making it work:
Example: http://jsfiddle.net/TUrvP/
There may be some overkill, and you may be able to use the
:animated
selector, though I had troubles at first.May not be worth the effort...
HTML
CSS
jQuery
看起来您正在寻找某种形式的 jQuery .animate 函数。
$('#clickme').hover(function() {
$('#book').animate({
不透明度:0.25,
左:'+=50',
高度:“切换”
}, 5000, 函数() {
// 动画完成。
});
});
否则慢慢切换类对我来说没有多大意义
It looks like you are looking for some form of .animate function of jQuery.
$('#clickme').hover(function() {
$('#book').animate({
opacity: 0.25,
left: '+=50',
height: 'toggle'
}, 5000, function() {
// Animation complete.
});
});
Otherwise switch class slowly doesnt makes much sense to me