<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.page{
width: 100vw;
height: 100vh;
background-color: #efefef;
position: fixed;
left: 0;
top: 0;
}
.menu{
width: 50vw;
height: 100vh;
position: fixed;
left: 0;
top: 0;
transform: translateX(100vw);
background-color: skyblue;
transition: transform 0.5s;
}
.active{
transform: translateX(50vw);
}
</style>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<div class="page">
首页
<button @click="toggleMenu" type="button">切换侧边栏</button>
</div>
<div class="menu" :class="{active:isShow}">
侧边栏
</div>
</div>
<script type="text/javascript">
let app = new Vue({
el:"#app",
data:{
isShow:false
},
methods:{
toggleMenu:function(){
this.isShow = !this.isShow;
}
}
})
</script>
</body>
</html>
08-23
2205
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-29
8170
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-07
2167
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-11
1633
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-26
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-14
3222
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-04
1883
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)