如何一次只打开一张手风琴幻灯片 [英] How to make only one accordion slide open at a time
问题描述
我有一个正在使用的网站,所有网站均基于手风琴式幻灯片.问题是我使用的代码默认情况下不会关闭打开的幻灯片.我需要它,以便在单击一张幻灯片时将其打开,然后在单击另一张幻灯片时将其关闭第一张幻灯片,依此类推.我从页面上发布了所有的JS,我可以添加些什么,使其一次只允许打开一张幻灯片?
I have a site I'm working on that is all based on accordion style slides. The problem is that the code I used does not close the open slides by default. I need it so that when you click one slide it opens and then when you click another it closes the first slide and so on. I posted all the JS from the page, what can I add to this to make it only allow one slide to be open at a time?
<script>
if ($(this).scrollTop() > 100) {
$('#up').fadeIn();
} else {
$('#up').fadeOut();
}
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('#up').fadeIn();
} else {
$('#up').fadeOut();
}
});
$('#up').click(function(){
$('html, body').animate({scrollTop:0}, 800);
});
</script>
<!-- Menu -->
<script>
$('.link').click(function() {
var link = $(this).attr('href');
$('html,body').animate({scrollTop: $(link).offset().top - 80}, 800);
});
</script>
<!-- Collapse Toogle -->
<script>
$('.accordion-toggle').click(function() {
$('html,body').animate({scrollTop: $(this).offset().top - 105}, 800);
});
推荐答案
您可以更改所单击项目的类.
You could change the class of the item clicked.
$('.accordion-toggle').click(function() {
for (c=0;c<$('.collapse').length;c++){
$("#"+$('.collapse')[c].id).collapse('hide');
}
$('html,body').animate({scrollTop: $(this).offset().top - 105}, 800);
});
因此,当您单击.menu-item
时,可以获得所有.menu-item-clicked
并将其更改为关闭.
So when you click at a .menu-item
you can get all .menu-item-clicked
and change them to close.
这篇关于如何一次只打开一张手风琴幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!