Jquery Slidetoggle - 似乎无法让它开始关闭?
我在单页网站上使用 jquery Slidetoggle。我一直试图找出我的脚本哪里出了问题,但似乎无法解决这个问题。我试图让幻灯片切换效果在页面打开时开始关闭,并且仅在单击时打开/关闭。现在,当页面打开时,幻灯片切换的每个部分都已经打开:/任何帮助将不胜感激。
<script type="text/javascript">
jQuery(function($) {
var openText = 'Open';
var closeText = 'Close';
$('.item-util .more-toggle').toggle(
function() {
$(this).html(closeText);
$(this).parent().siblings('div').slideToggle('slow');
},
function() {
$(this).html(openText);
var returnTo = $(this).parents('.item');
$.scrollTo(returnTo, {offset:{top:-150, left:0}, duration:600});
$(this).parent().siblings('div').slideToggle('slow');
}
);
});
</script>
谢谢
I am using a jquery slidetoggle on a single page website. I have been trying to figure out where I went wrong in my script but can't seem to resolve this issue. I am trying to get the slide toggle effect to start off closed when the page opens and open/close only on click. Right now, when the page opens each section of the slide toggle is already open :/ Any help would be appreciated.
<script type="text/javascript">
jQuery(function($) {
var openText = 'Open';
var closeText = 'Close';
$('.item-util .more-toggle').toggle(
function() {
$(this).html(closeText);
$(this).parent().siblings('div').slideToggle('slow');
},
function() {
$(this).html(openText);
var returnTo = $(this).parents('.item');
$.scrollTo(returnTo, {offset:{top:-150, left:0}, duration:600});
$(this).parent().siblings('div').slideToggle('slow');
}
);
});
</script>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将要开始关闭的元素的样式设置为
display:none
,它应该可以工作...Set the style of the elements you want to start closed as
display:none
and it should work...要使其以关闭状态开始,您需要将您尝试滑动的元素的 css 设置为
display: none;
。To have it start off as closed you need to set the css to
display: none;
for the element that you are trying to slide.