单击“ center
”容器或“ right
”容器(再次单击返回其状态)时,我无法弄清楚如何更改菜单元素的颜色。目前我的3条线是我的菜单中是白色的,我想将它们变为红色这些“时center
”和“right
被点击”容器。
菜单和容器的HTML:
<div class="menu">
<div class="line"></div>
<div class= "container" id= "center">
<h1 style="color:white"><a>LOREM IPSUM<a/></h1>
</div>
<div class="container" id= "right">
<h1 style="color:white"><a>LOREM IPSUM</a></h1>
</div>
菜单元素的CSS:
.menu .line {
height: 5px;
width: 40px;
background: #fff;
position: absolute;
top: 22.5px;
left: 5px;
-webkit-transition: all 250ms linear;
transition: all 250ms linear;
z-index: 100;
}
.menu .line:after, .menu .line:before {
content: ' ';
height: 5px;
width: 40px;
background: #fff;
position: absolute;
-webkit-transition: all 250ms linear;
transition: all 250ms linear;
}
.menu .line:before {
top: -10px;
}
.menu .line:after {
bottom: -10px;
}
为所需的颜色定义新的类,例如
.red {
color: red !important;
}
.green {
color: green !important;
}
然后使用jQuery切换它们:
$('#center').click(function() {
$(this).find('h1').toggleClass('red');
});
$('#right').click(function() {
$(this).find('h1').toggleClass('green');
});
注意:如果使用CSS分配原始颜色,则不需要!important。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句