实现效果:
实现效果如下图所示
实现原理:
什么是筋斗云效果:
•这个效果很简单,就是鼠标移到其他导航目录时会有背景图片跟着鼠标滑动到当前的目录。
实现思路:
•鼠标经过的时候,利用offsetLeft获得当前盒子距离左侧的距离,把这个值赋给缓动动画的end值。
•当点击的时候记住当前的offsetLeft值,当鼠标经过的时候把之前点击的offsetLeft给现在经过时候的值。
实现代码:
下面是实现代码以及详细注释,核心设置一个position为absolute的span标签,通过绑定鼠标事件,用封装好的animate动画实现span的“筋斗云”效果。
导航栏筋斗云效果 *{ padding: 0; margin: 0; } body{ background-color: rgba(0, 0, 0, 0.6); } .box{ width: 415px; height: 42px; margin: 200px auto; background-color: #fff; position: relative; } ul{ list-style: none; position: relative; } li{ float: left; width: 83px; height: 42px; text-align: center; font: 500 15px/42px "微软雅黑"; cursor: pointer; } span{ position: absolute; left: 0; top: 0; width: 83px; height: 42px; background-image: linear-gradient(to right,#03c03c 50% ,#51ee5d 100%); }
- 菜单栏1
- 菜单栏2
- 菜单栏3
- 菜单栏4
- 菜单栏5
总结
以上所述是小编给大家介绍的JavaScript实现精美个性导航栏筋斗云效果,希望对大家有所帮助!
以上就是JavaScript实现精美个性导航栏筋斗云效果的详细内容,更多请关注本站其它相关文章!