一、菜单常用的显示隐藏效果
完整代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| <!doctype html> <html> <head> <meta charset="utf-8"> <title>菜单点击隐藏与显示</title> <style> .container{ width: 1200px; margin: 20px auto; min-height: 700px; display: flex; padding: 0px; }
.left{ height: 700px; } .right{ padding: 0; flex: 1; background: #ffe; }
.left-container{ display: flex; height: 100%; flex-direction: row; flex-wrap: nowrap }
.left-container .left-menu{ background: #262626; overflow: hidden; transition: width 0.5s; height: 100%; color: #fff; text-align: center; } .left-container .icon-unfold{ color: aqua; } </style>
</head> <body> <div id="app">
<div class="container">
<div class="left" >
<div class="left-container"> <div class="left-menu" :style="{width:leftWidth+ 'px'}"> <p>我的菜单</p> <p>我的菜单</p> <p>我的菜单</p> <p>我的菜单</p> <p>我的菜单</p> <p>我的菜单</p> <p>我的菜单</p> </div> <div @click="unfoldNav" class="icon-unfold">{{text}}</div> </div> </div> <div class="right"> <p>正文........................</p> </div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { leftWidth: 250, text:"关闭" }, methods:{
unfoldNav: function () { this.leftWidth = this.leftWidth > 0 ? 0 : 250; this.text = this.text === "关闭" ? "展开" : "关闭"; } } })
</script>
</body> </html>
|
- 用到flex 布局,加上css3 width 变化的时间动画
您的打赏,是我创作的动力!不给钱?那我只能靠想象力充饥了。
微信支付
支付宝