如何取消jquery div点击效果
我对 div 施加了悬停效果。它所做的基本上就是增加 mouseenter 的高度,减少 mouseleave 的高度。
作为一个单独的功能,我将点击效果应用于其中一个 div:
$(function(){
$( '#div1 a' ).click(function() {
$( '.theRestofTheDivs' ).each(function() {
$(this).animate({height: "30px"}, 200);
})
});
});
它效果很好,除了当我鼠标离开时,它会折叠。显然这是因为我有之前的悬停效果。
单击后,我不想让它能够折叠,直到单击另一个带有锚点的 div。有什么想法吗?
编辑
提供的代码已简化,要在完整的上下文中查看它,请访问http:// /www.raceramps.com/v2
将鼠标悬停在“浏览全部”上,然后单击它。我不想让它崩溃。
I have a hover effect applied to a div. All it does is basically increase the height mouseenter, decrease the height mouseleave.
As a separate function, I have a click effect applied to one of the divs:
$(function(){
$( '#div1 a' ).click(function() {
$( '.theRestofTheDivs' ).each(function() {
$(this).animate({height: "30px"}, 200);
})
});
});
It works great, except when I mouseleave, it collapses. Obviously that is because I have the previous hover effect.
After it's been clicked, I don't want to allow it to be able to collapse until another div with an anchor is clicked. Any ideas?
EDIT
The code provided is simplified, to see it in the full context go to http://www.raceramps.com/v2
Mouseover "Browse All", then click it. I don't want it to collapse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将一个类放在单击的div上,并且仅在该类不存在的情况下折叠div
当单击另一个div时,您从前一个div中删除该类并将其添加到单击的div中
并在折叠部分添加此
You can put a class on the one clicked and only collapse divs if the class doesnt exist
When another div is clicked you remove the class from the previous div and add it to the one clicked
And on your collapsing part add this
假设您的基本标记看起来像这样:
您可以这样做:
类似这样的东西,或者像这样建模的东西应该可以工作。
Assuming your basic markup looks something like this:
You could do this:
Something like this, or modeled like this should work.