我在这里有一个脚本演示,它允许我在我的网站上显示和隐藏内容。它运行良好。
但是,当我单击链接以显示内容然后再次单击以隐藏它时,它会重新打开它。在显示(“活动”)状态下单击时,我需要它完全隐藏。
谁能解释如何解决这个问题?
谢谢你。
代码:
$(document).ready(function() {
$('.showscroll').bind('click', 'h2, h3', function(e) {
e.preventDefault();
$(this).toggleClass('active');
$('.newboxes2').slideUp().delay(200);
$(this).find('.newboxes2').slideToggle();
if($(this).is('.active') ) {
$(this).find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_onstate.png');
} else {
$(this).find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_offstate.png');
}
if (this.id === 'service29') {
$('html, body').animate({
scrollTop: $(this).find('h2').offset().top
}, 1000);
}
});
});