<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. [Selenium] Java代码获取屏幕分辨率

    import java.awt.Dimension; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java. ...

  2. JAVA array,map 转 json 字符串

    public class User { private String username; private String password; public String getUsername() { ...

  3. Problem of Uninstall Cloudera: Cannot Add Hdfs and Reported Cannot Find CDH's bigtop-detect-javahome

    1. Problem We wrote a shell script to uninstall Cloudera Manager(CM) that run in a cluster with 3 li ...

  4. oracle树形语句

    oracle树查询的最重要的就是select…start with…connect by…prior语法了.依托于该语法,我们可以将一个表形结构的以树的顺序列出来.在下面列述了oracle中树型查询的 ...

  5. 机器学习—SVM

    一.原理部分: 依然是图片~ 二.sklearn实现: import pandas as pd import numpy as np import matplotlib.pyplot as plt i ...

  6. 咏南中间件+开发框架支持最新的DELPHI 10.2 TOKYO

    咏南中间件+开发框架支持最新的DELPHI 10.2 TOKYO 价格十分优惠.有意者请向本人索取演示程序! 你只需花一套中间件的价格,就可获得:中间件,CS开发框架一套(赠送),BS开发框架一套(赠 ...

  7. Mahout学习资料

    Apache Mahout 简介 http://www.ibm.com/developerworks/cn/java/j-mahout/ 从源代码剖析Mahout推荐引擎 http://blog.fe ...

  8. [zepto]源码学习

    $() : zepto选择器,与jquery选择器类似,但是不支持jquery的拓展css支持(:first,:eq,:last...) $("div")选择页面内的全部div元素 ...

  9. django drf 自定义jwt用户验证逻辑

    新建Backend类 from django.contrib.auth.backends import ModelBackend from django.shortcuts import render ...

  10. Jenkins+.Net Core+Git集成发布 - SkyMallCore快速开发平台

    准备工作:安装 Jenkins+java 直接百度安装,在此忽略 dotnet sdk(iis部署已经安装) 一:windows 部署到IIS 首先搭建IIS,站点应用程序池选择 ‘无托管代码’ 安装 ...