简体   繁体   English

CSS切换效果

[英]CSS Toggle Effect

I have need help with the navigation for my site. 我需要有关网站导航的帮助。 Here's the link to the current code: http://jsfiddle.net/Sharon_J/cf2bm0vs/ 这是当前代码的链接: http : //jsfiddle.net/Sharon_J/cf2bm0vs/

What happens now is that when you click on the 'Plus' sign the sub menus under that category are shown but the sign remains as it is. 现在发生的是,当您单击“加号”符号时,显示了该类别下的子菜单,但该符号保持原样。 The 'Plus' sign should turn in to 'Minus' on click. 单击时,“加号”应变成“减号”。 I have tried to apply JavaScript to get the effect, but its not working. 我试图应用JavaScript来获得效果,但是它不起作用。 Can anyone suggest something? 有人可以建议吗?

Can the following code be somehow modified for the required effect? 可以对以下代码进行某种修改以达到所需的效果吗?

.toggle, [id^=drop]{
display: none;
}

[id^=drop]:checked + ul{

    display:block;

}

here is your solutions please check jsfiddle. 这是您的解决方案,请检查jsfiddle。 http://jsfiddle.net/cf2bm0vs/3/ http://jsfiddle.net/cf2bm0vs/3/

add this script : 添加此脚本:

 $('.toggle').not('.tog1').on('click',function(){
    if($(this).hasClass('open')){
      $(this).removeClass('open');
      $(this).html('+');
    }else{
      $(this).addClass('open');
      $(this).html('-');
    }
})

you can try this one: 您可以尝试以下一种方法:

$('.toggle').click(function() {
  $('.tog1').toggleClass('toggled');
});

DEMO FIDDLE 演示场

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM