要写一个下拉菜单点击按钮 菜单进口就是是点击一个图标按钮 之前都是随意用个图片替代 本日倏忽想用CSS写个结果 重要参考汹涌挪动端右上角的按钮
结果:
HTML
//vue 中经由过程点击事宜转变class <div class="burger" style="float: right;" :class="{'transform':rightTopBtn}" @click.stop="rightTopBtn=!rightTopBtn" > <div></div> <div></div> <div></div> </div>CSS
<!--按钮容器 START--> .burger { cursor: pointer; display: inline-block; margin: 7px 6px 0 0; outline: none; } <!--按钮容器 END--> <!--三条横线 经由过程rotate3d完成扭转 START--> .burger p { width: 30px; height: 4px; margin-bottom: 6px; background-color: rgb(51, 51, 51); transform: rotate3d(0, 0, 0, 0); } <!--三条横线 END--> .burger.transform p { background-color: transparent; } .burger.transform p:first-of-type { top: 10px; transform: rotate3d(0, 0, 1, 45deg) } .burger.transform p:last-of-type { bottom: 10px; transform: rotate3d(0, 0, 1, -45deg) } <!--点击后第一个和第三个横线的结果 START--> .burger.transform p:first-of-type, .burger.transform p:last-of-type { transition: transform .4s .3s ease, background-color 250ms ease-in; background: #00c1de; } <!--点击后第一个和第三个横线的结果 END--> <!--作废点击后恢复动画 START--> .burger p:first-of-type, .burger p:last-of-type { transition: transform .3s ease .0s, background-color 0ms ease-out; position: relative; } <!--作废点击后恢复动画 END-->
只用transition也是能到达 animation的结果的 经由过程设置差别属性的变化 控制好变化时候 和延时的时候 就能够让动画有先后顺序
以上就是CSS完成菜单按钮动画的代码示例的细致内容,更多请关注ki4网别的相干文章!