js 弹性导航
<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 弹性导航的更多相关文章
- js实现滑动的弹性导航
		<!doctype html> <html> <head> <meta charset="utf-8"> <title> ... 
- Js弹性漂浮广告代码
		<html><head><meta http-equiv="Content-Type" content="text/html; charse ... 
- js实现导航固定定位
		js实现导航固定定位 <!DOCTY ... 
- js二级导航下拉菜单
		<!DOCTYPE html> <html> <head> <title>导航列表</title> <meta http-equiv= ... 
- js二级导航
		js写二级导航要点 1.ul li 2.js获取元素 3.setInterval(function(),time); 代码如下 <style type="text/css"& ... 
- 用js实现导航菜单点击切换选中时高亮状态
		随着用户点击导航或菜单上不同的页面,出现此选项高亮显示或变为一个新的样式是经常用到的.实现它所用的原理就是通过js中的location.href得到当前页面的地址,然后在与导航上的链接地址匹对,相同的 ... 
- jquery.nav.js定位导航滚动插件
		jQuery.nav.js插件代码: /* * jQuery One Page Nav Plugin * http://github.com/davist11/jQuery-One-Page-Nav ... 
- js动态控制导航栏样式
		导航栏一般做为母版页,为了使增加用户体验,往往在用户进入某个页面给予导航栏相应的样式,这里可以用js动态添加 <div class="box_left fl"> < ... 
- JS面向对象方法(一): 使用原生JS 实现导航栏下多级分类弹出效果
		利用二级菜单的onmouseover/out事件 重新构建一级菜单 ".hover" 样式类 代码如下: CSS部分: 在原来的目标:hover样式中 增加 .hover状态 li ... 
随机推荐
- YUI前端优化原则-cookie与图像
			四.图片.Coockie与移动应用篇 除此之外,图片和Coockie也是我们网站中几乎不可缺少组成部分,此外随着移动设备的流行,对于移动应用的优化也十分重要.这主要包括:Coockie: 减小Cook ... 
- Java 设计模式系列(十八)备忘录模式(Memento)
			Java 设计模式系列(十八)备忘录模式(Memento) 备忘录模式又叫做快照模式(Snapshot Pattern)或Token模式,是对象的行为模式.备忘录对象是一个用来存储另外一个对象内部状态 ... 
- linux  修改oracle字符集
			问题描述:同事在Linux下安装的Oracle,默认的字符集没有修改,使用的是WE8ISO8859P1,不能够支持中文, 问题表现为,客户端录入的中文数据可以显示,提交之后再查询出来后中文会显示为?? ... 
- java消息中间件的使用与简介
			一.为什么要使用消息中间件 消息中间件就是可以省去繁琐的步骤,直达目的,怎么讲呢,就是比如你想很多人,知道你的动态,而知道的人可能手机没电,可能手机信号不好,可能手机不在服务区,或者看的人比较忙,看的 ... 
- iOS9 视频播放
			self.videoFileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:///%@", self ... 
- shell 脚本 查看班上同学的网络状态
			#!/bin/base # a=192.168.100. //定义变量 c=('王浩' '谢云生' '黄科杨' '何星宇' '张宸兵' '胡燕' '刘桃') //定义数组 for b in {101. ... 
- 12、Docker的网络--bridge
			单机网络 Bridge Network Host Network None Network 多机网络 Overlay Network 12.1 网络命名空间 启动一个容器 docker run - ... 
- 5、Docker架构和底层技术
			5.1 Docker Platform Docker提供了一个开发,打包,运行APP的平台 把APP和底层infrastructure隔离开来 5.2 Docker Engine 后台进程(docke ... 
- 浏览器缓存和Service Worker
			浏览器缓存和Service Worker @billshooting 2018-05-06 字数 6175 Follow me on Github 标签: BOM 1. 传统的HTTP浏览器缓存策略 ... 
- How to generate HMAC-SHA1 in C#?
			using (HMACSHA1 m = new HMACSHA1(Encoding.UTF8.GetBytes("AKIDZfbOA78asKUYBcXFrJD0a1ICvR98JM&quo ... 
