<style>
*{margin:0;padding:0;}
#box{height:50px;float:left;position:relative;background:#f90;}
#bar{width:64px;height:100%;position:absolute;left:0;top:0;background:#333;}
#bar .l{width:0;height:100%;background:#333;border-radius:50%;position:absolute;top:0;left:0;}
#bar .r{width:0;height:100%;background:#333;border-radius:50%;position:absolute;top:0;right:0;}
#ul{height:100%;font-size:14px;letter-spacing:1px;font-family:"微软雅黑";list-style:none;position:relative;}
#ul li{height:100%;line-height:50px;float:left;}
#ul a{height:100%;text-decoration:none;color:#fff;padding:0 20px;display:block;}
</style>
<div id="box">
<div id="bar">
<div class="l"></div>
<div class="r"></div>
</div>
<ul id="ul">
<li><a href="#1">祝</a></li>
<li><a href="#2">大家</a></li>
<li><a href="#3">在2018</a></li>
<li><a href="#4">能顺利</a></li>
<li><a href="#5">掌握</a></li>
<li><a href="#6">javaScript</a></li>
</ul>
</div>
<script>
var oBar=document.getElementById("bar"),
oRight=oBar.getElementsByClassName("r")[0],
oLeft=oBar.getElementsByClassName("l")[0],
oUl=document.getElementById("ul"),
aLi=oUl.getElementsByTagName("li"),
iNow=1;//表示当前哪项高亮
oBar.style.left=aLi[iNow].offsetLeft+"px";
oBar.style.width=aLi[iNow].offsetWidth+"px";
for(var i=0;i<aLi.length;++i){
aLi[i].index=i;
aLi[i].onmouseover=function(){
lesgo(this);
};
}
oUl.onmouseout=function(){
lesgo(aLi[iNow]);
};
function lesgo(oLi){//效果主要函数
var t=Math.abs(oLi.offsetLeft-oBar.offsetLeft)*0.7;
move(oBar,{left:oLi.offsetLeft,width:oLi.offsetWidth},t,"easeOut",function(){
move(oRight,{width:0,right:0},80,"linear",function(){
oRight.style.background="#f90";
move(oRight,{width:20,right:-10},80,"linear",function(){
move(oRight,{width:0,right:0},50,"linear");
});
});
move(oLeft,{width:0,left:0},80,"linear",function(){
oLeft.style.background="#f90";
move(oLeft,{width:20,left:-10},80,"linear",function(){
move(oLeft,{width:0,left:0},50,"linear");
});
});
});
if(oLi.offsetLeft > oBar.offsetLeft){
console.log(oLi.offsetLeft);
console.log(oBar.offsetLeft);
setColor('#333','#f90'); }else if(oLi.offsetLeft < oBar.offsetLeft){
setColor('#f90','#333');
}
function setColor(color1,color2){
oRight.style.background = color1;
oLeft.style.background = color2;
move(oRight,{width:40,right:-20},150);
move(oLeft,{width:40,left:-20},150);
}
} //下面都是运动库相关move(元素,属性json,时间,运动类型,运动结束函数)
function move(t, n, e, r, a) {
clearInterval(t.iTimer);
var u = e || 1e3,
i = {};
for (var o in n) i[o] = {}, "opacity" == o ? (i[o].b = Math.round(100 * css(t, o)), i[o].c = 100 * n[o] - i[o].b) : (i[o].b = parseInt(css(t, o)), i[o].c = n[o] - i[o].b);
var r = r || "linear",
c = (new Date).getTime();
t.iTimer = setInterval(function() {
var e = (new Date).getTime() - c;
e >= u && (e = u);
for (var o in n) {
var f = Tween[r](e, i[o].b, i[o].c, u);
"opacity" == o ? (t.style[o] = f / 100, t.style.filter = "alpha(opacity=" + f + ")") : t.style[o] = f + "px"
}
e == u && (clearInterval(t.iTimer), a && a.call(t))
}, 14) }
function css(t, n) {
return t.currentStyle ? t.currentStyle[n] : getComputedStyle(t, !1)[n]
}
var Tween = {
linear: function(t, n, e, r) {
return e * t / r + n
},
easeIn: function(t, n, e, r) {
return e * (t /= r) * t + n
},
easeOut: function(t, n, e, r) {
return -e * (t /= r) * (t - 2) + n
},
easeBoth: function(t, n, e, r) {
return (t /= r / 2) < 1 ? e / 2 * t * t + n : -e / 2 * (--t * (t - 2) - 1) + n
},
easeInStrong: function(t, n, e, r) {
return e * (t /= r) * t * t * t + n
},
easeOutStrong: function(t, n, e, r) {
return -e * ((t = t / r - 1) * t * t * t - 1) + n
},
easeBothStrong: function(t, n, e, r) {
return (t /= r / 2) < 1 ? e / 2 * t * t * t * t + n : -e / 2 * ((t -= 2) * t * t * t - 2) + n
},
elasticIn: function(t, n, e, r, a, u) {
if (0 === t) return n;
if (1 == (t /= r)) return n + e;
if (u || (u = .3 * r), !a || a < Math.abs(e)) {
a = e;
var i = u / 4
} else var i = u / (2 * Math.PI) * Math.asin(e / a);
return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin(2 * (t * r - i) * Math.PI / u)) + n
},
elasticOut: function(t, n, e, r, a, u) {
if (0 === t) return n;
if (1 == (t /= r)) return n + e;
if (u || (u = .3 * r), !a || a < Math.abs(e)) {
a = e;
var i = u / 4
} else var i = u / (2 * Math.PI) * Math.asin(e / a);
return a * Math.pow(2, -10 * t) * Math.sin(2 * (t * r - i) * Math.PI / u) + e + n
},
elasticBoth: function(t, n, e, r, a, u) {
if (0 === t) return n;
if (2 == (t /= r / 2)) return n + e;
if (u || (u = .3 * r * 1.5), !a || a < Math.abs(e)) {
a = e;
var i = u / 4
} else var i = u / (2 * Math.PI) * Math.asin(e / a);
return 1 > t ? -.5 * a * Math.pow(2, 10 * (t -= 1)) * Math.sin(2 * (t * r - i) * Math.PI / u) + n : a * Math.pow(2, -10 * (t -= 1)) * Math.sin(2 * (t * r - i) * Math.PI / u) * .5 + e + n
},
backIn: function(t, n, e, r, a) {
return "undefined" == typeof a && (a = 1.70158), e * (t /= r) * t * ((a + 1) * t - a) + n
},
backOut: function(t, n, e, r, a) {
return "undefined" == typeof a && (a = 2.0158), e * ((t = t / r - 1) * t * ((a + 1) * t + a) + 1) + n
},
backBoth: function(t, n, e, r, a) {
return "undefined" == typeof a && (a = 1.70158), (t /= r / 2) < 1 ? e / 2 * t * t * (((a *= 1.525) + 1) * t - a) + n : e / 2 * ((t -= 2) * t * (((a *= 1.525) + 1) * t + a) + 2) + n
},
bounceIn: function(t, n, e, r) {
return e - Tween.bounceOut(r - t, 0, e, r) + n
},
bounceOut: function(t, n, e, r) {
return (t /= r) < 1 / 2.75 ? 7.5625 * e * t * t + n : 2 / 2.75 > t ? e * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + n : 2.5 / 2.75 > t ? e * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + n : e * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + n
},
bounceBoth: function(t, n, e, r) {
return r / 2 > t ? .5 * Tween.bounceIn(2 * t, 0, e, r) + n : .5 * Tween.bounceOut(2 * t - r, 0, e, r) + .5 * e + n
}
};
</script>

更多前端效果:https://xue-y.github.io/fore-end/

js 弹性导航的更多相关文章

  1. js实现滑动的弹性导航

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Js弹性漂浮广告代码

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  3. js实现导航固定定位

                                                                                   js实现导航固定定位 <!DOCTY ...

  4. js二级导航下拉菜单

    <!DOCTYPE html> <html> <head> <title>导航列表</title> <meta http-equiv= ...

  5. js二级导航

    js写二级导航要点 1.ul li 2.js获取元素 3.setInterval(function(),time); 代码如下 <style type="text/css"& ...

  6. 用js实现导航菜单点击切换选中时高亮状态

    随着用户点击导航或菜单上不同的页面,出现此选项高亮显示或变为一个新的样式是经常用到的.实现它所用的原理就是通过js中的location.href得到当前页面的地址,然后在与导航上的链接地址匹对,相同的 ...

  7. jquery.nav.js定位导航滚动插件

    jQuery.nav.js插件代码: /* * jQuery One Page Nav Plugin * http://github.com/davist11/jQuery-One-Page-Nav ...

  8. js动态控制导航栏样式

    导航栏一般做为母版页,为了使增加用户体验,往往在用户进入某个页面给予导航栏相应的样式,这里可以用js动态添加 <div class="box_left fl"> < ...

  9. JS面向对象方法(一): 使用原生JS 实现导航栏下多级分类弹出效果

    利用二级菜单的onmouseover/out事件 重新构建一级菜单 ".hover" 样式类 代码如下: CSS部分: 在原来的目标:hover样式中 增加 .hover状态 li ...

随机推荐

  1. [Java] 获取当前Project所在的路径

    String projectPath = System.getProperty ("user.dir").toString()

  2. [Selenium]等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的

    等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的 /** * Check if the element present with cu ...

  3. etl使用表

    select * from etl_data_map t;select * from etl_column t;select * from etl_table_def t;select * from ...

  4. Java程序设计16——Annotatio注释

    Annotation是代码里的特殊标记,这些标记可以在编译.类加载.运行时被读取,并执行相应的处理.通过使用Annotation,程序开发人员可以在不改变原有逻辑的情况下,在源文件嵌入一些补充信息.代 ...

  5. Mybatis之整体描述

    Mybatis在我看来最大的用处就是封装了jdbc,设置参数操作和获取解析结果集.同时控制了数据库链接等操作,大部分采用了反射来映射javabean对象来进行数据库操作. 1.接下来先整体介绍下主要的 ...

  6. eclipse启动tomcat出现内存溢出错误 java.lang.OutOfMemoryError: PermGen space

    发布工程后,启动tomcat出现如下内存溢出错误: java.lang.OutOfMemoryError: PermGen space ... java.lang.OutOfMemoryError: ...

  7. 阿里杨传辉的访问节选(oceanbase)

    皮皮(Q4): OceanBase第一个应用是收藏夹.最近,听说支付宝交易也用到了OceanBase.能否结合阿里的应用谈谈OceanBase的优势. 杨传辉(A4):相比传统的关系数据库,谈及Oce ...

  8. StringFormate使用

    1常规类型的格式化 1.1显示不同转换符实现不同数据类型到字符串的转换 转换符   说明 示例 %s     字符串类型 “mingrisof” %c     字符类型 'm' %b 布尔类型 tru ...

  9. Android-有序广播明确指定接收者

    在上一篇博客,Android-有序广播是可以中断的,介绍了 有序广播是可以中断的,但还有一种例外情况:明确指定接收者的有序广播是无法中断的,一定会发送到指定的接收者 AndroidManifest.x ...

  10. CDH源代码

    CDH Packaging and Tarball Information http://www.cloudera.com/content/cloudera/en/documentation/core ...