[英]Making JQuery horizontal accordion close on click
Example: http://vincent-massaro.com/map/ 示例: http : //vincent-massaro.com/map/
Currently, the script allows you to click on a piece of the accordion to open it, but it is set to close on mouseleave. 当前,该脚本允许您单击手风琴的一部分以将其打开,但是设置为在mouseleave上关闭。 When I set the mouseleave to .click, it gets confused and doesn't know what state it is in. I want to make it so that you can click to open it, and click to close it, instead of mouseleave.
当我将mouseleave设置为.click时,它会感到困惑,并且不知道它处于什么状态。我想要创建它,以便您可以单击以将其打开,然后单击以关闭它,而不是mouseleave。 The code controlling this is below, and the full script is in haccordion.js linked in the page source.
控制它的代码在下面,完整的脚本在页面源代码中链接的haccordion.js中。 If someone could help me modify this script, I would be very grateful!
如果有人可以帮助我修改此脚本,我将不胜感激! Thanks in advance.
提前致谢。
$target.click(function(){
haccordion.expandli(config.accordionid, this)
config.$lastexpanded=$(this)
})
if (config.collapsecurrent){ //if previous content should be contracted when expanding current
$target.mouseleave(function(){
$(this).stop().animate({width:config.paneldimensions.peekw}, config.speed)
})
}
You could set a boolean variable to represent whether the accordion is open or not and just check it on click. 您可以设置一个布尔变量来表示手风琴是否打开,然后单击即可检查。 (You'll need to toggle the variable's state on click too)
(您也需要在点击时切换变量的状态)
Edit: 编辑:
Ok try this. 好的,尝试一下。 Set a boolean global variable (outside the click event) like this:
像这样设置一个布尔全局变量(在click事件之外):
var accordion_expanded = false;
Then within your click event do something like this: (I haven't tested this so you might have to massage it a bit to fit your circumstance) 然后在您的click事件中执行以下操作:(我尚未对此进行测试,因此您可能需要对其进行一些调整以适合您的情况)
In the function where you expand your accordion put this: 在扩展手风琴的功能中输入以下内容:
accordion_expanded = true;
And in the function where you contract your accordion do a 在签约手风琴的功能中,
if(accordion_expanded == true){
//Contract accordion code goes here
accordion_expanded == false;
}
Good Luck! 祝好运!
try use this 试试这个
$('.accordion-item-header').click(function() {
var item = $(this).parent().find('.accordion-item-body');
item.toggleClass('open').animate({
width:item.hasClass('open') ? 0: 100
}, 100).toggleClass('open');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.