我有一个 javascript 函数,它是这样的:function toggle() { $('.sidebar').toggle();}我可以为侧边栏添加一些 css:.sidebar { transform: translate3d(-280px, 0px, 0px); position: absolute; width: 280px; background: #263249; color: #eee; left: 0; height: 100%; transition: all .3s;}这个侧边栏现在是隐藏的,但是当我运行切换功能时,我需要它来切换这个值:transform: translate3d(0px, 0px, 0px);我怎样才能做到这一点?
1 回答
![?](http://img1.sycdn.imooc.com/533e4d00000171e602000200-100-100.jpg)
繁华开满天机
TA贡献1816条经验 获得超4个赞
您可以使用 toggleClass
function toggle() {
$('.sidebar').toggleClass('newValue');
}
.sidebar {
transform: translate3d(-280px, 0px, 0px);
position: absolute;
width: 280px;
background: #263249;
color: #eee;
left: 0;
height: 100%;
transition: all .3s;
}
.newValue {
transform: translate3d(0px, 0px, 0px);
}
添加回答
举报
0/150
提交
取消