这是一个棘手的问题!我花了几个小时在这个,在Stackoverflow找不到类似的东西,可能是因为我不知道要搜索什么。如果一个或两个盒子打开/关闭,打开/关闭剩余部分(如果全部打开,全部关闭)
问题:
在容器中,我有3个箱子,每个具有开/关切换按钮 - 即单独切换它们 - 它工作正常。
我有一个打开关闭所有按钮的容器外,应该能够打开剩余的盒子
(if 1 or 2 are already open)
或者如果所有/或没有打开,它应该打开/关闭它们全部。
我的代码几乎不,我需要(if 1 or 2 boxes are open and you click Open-Close All, the remainder opens)
,如果所有的箱子都关闭,开闭打开它们一下子一切。
唯一不起作用的是,如果所有框都打开,我希望能够通过单击打开全部关闭一次全部关闭它们。
http://codepen.io/StrengthandFreedom/pen/ZbrvOO
$('.small-box-button').on('click', function(){
event.preventDefault();
$(this).next('.small-box').toggleClass('is-visible');
});
// Open/Close all/remainders
$('.open-close-all-button').on('click', function(){
event.preventDefault();
if ($('.small-box').is(':visible')) {
// then open the small boxes that are not open yet (the remainders)
$('.small-box').siblings().addClass('is-visible');
// $(this).next('.small-box').toggleClass('is-visible');
}
//not sure what to do here...
else ($('.small-box').not(':visible'))
$('.small-box').siblings().addClass('is-visible');
});
我想我需要多用一些的if else条件和检查值(like if isVisible >= 1 || 2)
,但不知道怎么写。 我有一种感觉,这可以写得更简单。
真的很感谢一些指导,我尽我所能让示例尽可能容易地看。
谢谢! :-)
叶青什么,应该是可行的.... – AdamJeffers
有你的代码中没有“打开/关闭”按钮钢笔? – AdamJeffers