筋斗云导航栏
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{margin: 0; padding: 0;}
ul {list-style:none;}
body {
background-color: #000;
}
.nav {
width: 800px;
height: 42px;
background:url("https://img2.baidu.com/it/u=3576395785,3231005464&fm=26&fmt=auto") no-repeat right center #fff;
background-size: 83px 42px;
margin: 100px auto;
border-radius: 5px;
position: relative;
}
.cloud {
width: 83px;
height: 42px;
position: absolute;
top: 0;
left: 0;
background: url(https://img0.baidu.com/it/u=1439941641,1757111083&fm=26&fmt=auto) no-repeat;
background-size: 83px 42px;
}
.nav ul {
position: absolute;
top: 0;
left: 0;
}
.nav li {
float: left;
width: 83px;
height: 42px;
line-height: 42px;
text-align: center;
color: #000;
cursor: pointer;
}
</style>
</head>
<body>
<div class="nav" id="nav">
<span class="cloud" id="cloud"></span>
<ul>
<li>首页新闻</li>
<li>师资力量</li>
<li>活动策划</li>
<li>企业文化</li>
<li>招聘信息</li>
<li>公司简介</li>
<li>上海校区</li>
<li>广州校区</li>
</ul>
</div>
</body>
</html>
<script>
var cloud = document.getElementById("cloud"); // 云彩
var nav = document.getElementById("nav");
var lis = nav.children[1].children;
var current = 0; // 用于存放点击时候的 offsetLeft
//alert(lis.length);
// 2.循环遍历li
for(var i=0; i<lis.length;i++) {
lis[i].onmouseover = function() {
// alert(this.offsetLeft);
target = this.offsetLeft; // 把左侧的位置 ,给 target
};
lis[i].onmouseout = function() {
target = current; // 鼠标离开 target 是 刚才我们点击的位置
};
lis[i].onclick = function() {
current = this.offsetLeft; // 点击的时候 吧当前位置 存贮一下
}
}
//1. 缓动公式开启定时器
var leader = 0, target = 0;
setInterval(function(){
leader = leader + (target - leader ) / 10;
cloud.style.left = leader + "px";
},10);
</script>
仿淘宝关闭二维码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
position: relative;
width: 74px;
height: 88px;
border : 1px solid #cccccc;
margin: 100px auto;
font-size: 12px;
text-align: center;
color: #f40;
/* display: block; */
}
.box img {
/* position: relative; */
width: 60px;
margin-top: 5px;
}
.close-btn {
position: absolute;
top: 18px;
left: 79px;
width: 14px;
height: 14px;
border: 1px solid #cccccc;
line-height: 14px;
font-family: Arial, Helvetica, sans-serif;
cursor: pointer;
}
</style>
</head>
<body>
<div class="box">
淘宝二维码
<img src="https://img0.baidu.com/it/u=2217966656,379540428&fm=26&fmt=auto" alt="">
<i class="close-btn">X</i>
</div>
<script>
//1.获取元素
var btn = document.querySelector('.close-btn');
var box = document.querySelector('.box');
btn.onclick = function() {
//this 指向函数的调用者
box.style.display = 'none';
}
</script>
</body>
</html>