简体   繁体   English

单击下拉菜单时箭头转180度

[英]Arrow turning 180deg when clicking on dropdown menu

I have a dropdown menu and want the arrow on the right of it to turn 180deg when I click on it! 我有一个下拉菜单,当我点击它时,想要它右边的箭头转180deg! The problem is I've set the arrow in the html and not in the javascript.. But I thought there was maybe a way to put it in the css when going from #navi to #navigation.. 问题是我在html中设置了箭头,而不是在javascript中。但我认为从#navi转到#navigation时可能有一种方法可以将它放在css中。

Here's my code 这是我的代码

 <script> $(document).ready(function(){ $("#navi").click(function(){ $("#navigation").slideToggle(500); }); }); </script> 
 #navi{ margin-top:10px; margin-left:20px; width:170px; height:30px; line-height:30px; padding-left:10px; overflow:hidden; color:{color:Navigation}; background:{color:Navigation background}; font-size:12px; text-align:left; } #navi i{ position:absolute; margin-left:77px; margin-top:10px; color:{color:Navigation}!important; font-size:12px; } #navigation{ margin-top:10px; margin-left:20px; width:180px; overflow:hidden; display:none; font-size:12px; background:{color:Navigation background}; } #navigationin a{ display:block; font-size:12px; line-height:18px; width:180px; overflow:hidden; color:{color:Navigation link}; border-bottom:1px solid {color:Wide sidebar background}; padding:5px; text-align:center; } #navigationin a:hover{ box-shadow: inset 180px 0 0 0 {color:Wide sidebar background}; color:{color:Hover}; -webkit-transition: all .7s ease-in-out; -moz-transition: all .7s ease-in-out; -o-transition: all .7s ease-in-out; transition: all .7s ease-in-out; } #navigationin a{ -webkit-transition: all .7s ease-in-out; -moz-transition: all .7s ease-in-out; -o-transition: all .7s ease-in-out; transition: all .7s ease-in-out; } 
 <div id="navi"> NAVIGATION <i class="fa fa-chevron-down"></i></div> <div id="navigation"> <div id="navigationin"> 

Sorry I can't seem to make it work.. Thank you for any help you can give! 对不起,我似乎无法使它工作..感谢您提供任何帮助!

(if you want the actual exemple it's on www.typhotoshop.tumblr.com in the left hovering bar) (如果你想在左侧悬停栏上的www.typhotoshop.tumblr.com上有实际的例子)

All you have to do is , adding css3 transition on your arrow , and adding/removing a custom class to this last to rotate 180° , in which the transition is triggered. 您所要做的就是,在箭头上添加css3过渡,并在此最后添加/删除自定义类以旋转180°,其中将触发过渡。

#navi .fa-chevron-down {
  transition: all 0.5s ease;
}
.rtoate180 {
  transform: rotate(180deg);
}

add in js the toggleclass when click on navi 单击navi时在js中添加toggleclass

$("#navi .fa-chevron-down").toggleClass("rtoate180");

bellow working snippet : 轰鸣声工作片段:

 $(document).ready(function(){ $("#navi").click(function(){ $("#navi .fa-chevron-down").toggleClass("rtoate180"); $("#navigation").stop().slideToggle(500); }); }); 
 #navi .fa-chevron-down { transition: all 0.5s ease; } .rtoate180 { transform: rotate(180deg); } #navi{ margin-top:10px; margin-left:20px; width:170px; height:30px; line-height:30px; padding-left:10px; overflow:hidden; color:{color:Navigation}; background:{color:Navigation background}; font-size:12px; text-align:left; } #navi i{ position:absolute; margin-left:77px; margin-top:10px; color:{color:Navigation}!important; font-size:12px; } #navigation{ margin-top:10px; margin-left:20px; width:180px; overflow:hidden; display:none; font-size:12px; background:{color:Navigation background}; } #navigationin a{ display:block; font-size:12px; line-height:18px; width:180px; overflow:hidden; color:{color:Navigation link}; border-bottom:1px solid {color:Wide sidebar background}; padding:5px; text-align:center; } #navigationin a:hover{ box-shadow: inset 180px 0 0 0 {color:Wide sidebar background}; color:{color:Hover}; -webkit-transition: all .7s ease-in-out; -moz-transition: all .7s ease-in-out; -o-transition: all .7s ease-in-out; transition: all .7s ease-in-out; } #navigationin a{ -webkit-transition: all .7s ease-in-out; -moz-transition: all .7s ease-in-out; -o-transition: all .7s ease-in-out; transition: all .7s ease-in-out; } 
 <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="navi"> NAVIGATION <i class="fa fa-chevron-down"></i> </div> <div id="navigation"> <ul> <li>menu</li> <li>menu</li> <li>menu</li> </ul> </div> <div id="navigationin"></div> 

you can use css to do your desire output as well 你也可以用css来做你想要的输出

 margin-top: 100px;
 transform: rotateY(180deg);

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

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