[英]jQuery Accordion tab doesn't close
Can someone explain why my jQuery Accordion isn't closing? 有人能解释为什么我的jQuery Accordion没有关闭吗?
See the tab that is open
on page load. 请参阅页面加载时
open
的选项卡。 When I try to close, it keeps re-opening. 当我试图关闭时,它会不断重新打开。 Help?!
救命?!
http://jsfiddle.net/02vz11f0/ http://jsfiddle.net/02vz11f0/
Here's my jQuery : 这是我的jQuery :
$(document).ready(function ($) {
$('#accordion').find('.accordion-toggle').click(function () {
$(this).next().slideToggle('fast', function () {
var status = $(this).is(':hidden') ? 'open' : 'close';
$(this).prev('h4').find('.accordion-status').html(status);
});
});
});
CSS: CSS:
/* Separate component file for Accordion? */
/* line 72, sass/_layout.scss */
#accordion {
width: 100%;
}
/* line 73, sass/_layout.scss */
.accordion-content {
display: none;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding: 50px;
}
/* line 80, sass/_layout.scss */
.accordion-content.default {
display: block !important;
}
/* line 82, sass/_layout.scss */
.accordion-status {
position: absolute;
top: 30px;
right: 30px;
}
/* line 88, sass/_layout.scss */
.accordion-toggle {
cursor: pointer;
position: relative;
padding: 35px 60px 35px 0;
margin: 0;
}
/* line 94, sass/_layout.scss */
.accordion-toggle span {
margin-left: 60px;
color: #ffffff;
}
You need to remove the default
class from the element within the .slideToggle()
callback. 您需要从
.slideToggle()
回调中的元素中删除default
类。
$('#accordion').find('.accordion-toggle').click(function () {
$(this).next().slideToggle('fast', function () {
var status = $(this).is(':hidden') ? 'open' : 'close';
$(this).removeClass('default').prev('h4').find('.accordion-status').html(status);
});
});
In your CSS, you had the following: 在CSS中,您有以下内容:
.accordion-content.default {
display: block !important;
}
Which was preventing the content from being toggled. 这阻止了内容被切换。
You could also just remove !important
, and it will work as expected too. 您也可以删除
!important
,它也会按预期工作。 You should avoid using it as much as possible. 你应该尽可能避免使用它。
You need to remove !important
from: 你需要删除
!important
来自:
.accordion-content.default {
display: block !important;
}
It is overriding the action of the accordion. 它压倒了手风琴的动作。
Demo: http://jsfiddle.net/02vz11f0/1/ 演示: http : //jsfiddle.net/02vz11f0/1/
As I put in the comment, it is the !important
rule on your CSS selector .accordion-content.default
. 正如我在评论中所说,它是CSS选择器
.accordion-content.default
上的!important
规则。 It overrides jQuery hiding the div. 它覆盖了隐藏div的jQuery。 See this link as to how !important always overrides that property.
请参阅此链接以了解如何!important始终覆盖该属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.