我正在使用Slide Down&Up,效果很好。但是我的问题是,当用户打开此页面时,如果用户单击则它会向上滑动,然后只能向下滑动。
<script type="text/javascript">
jQuery(function ($) {
$(".block-layered-nav dt").click(function () {
if ($(this).next("dd").css("display") == "none") {
$(this).next("dd").slideDown(1000);
$(this).removeClass("closed");
} else {
$(this).next("dd").slideUp(1000);
$(this).addClass("closed");
}
});
});
</script>
我犯了什么错误
closed
用元素添加类
工作演示
jQuery(function($) {
$('dd').hide()
$(".navigation dt").click(function() {
if ($(this).next('dd').is(":visible")) {
$(this).next('dd').slideToggle('slow').toggleClass('close');
} else {
$(this).next('dd').slideToggle('slow').toggleClass('close');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="navigation">
<dt>test</dt>
<dd class="close">sample</dd>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句