您好,欢迎访问一九零五行业门户网

每天一个JS 小demo之滑屏幻灯片主要知识点:event

<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>document</title>
<style type=text/css>
body {
margin: 0;
}
#wrap {
margin: 100px auto;
position: relative;
width: 400px;
height: 300px;
border: 5px solid #000;
overflow: hidden;
}
#list {
position: absolute;
left: 0;
top: 0;
width: 400%;
list-style: none;
padding: 0;
margin: 0;
}
#list li {
width: 25%;
float: left;
}
img {
vertical-align: top;
}
#navs {
position: absolute;
left: 0;
bottom: 30px;
height: 12px;
width: 100%;
text-align: center;
}
#navs a {
display: inline-block;
width: 12px;
height: 12px;
vertical-align: top;
background: #fff;
margin: 0 5px;
border-radius: 6px;
}
#navs .active {
background: #f60;
}
</style>
</head>
<body>
<!--
练习:
1. 实现自动播放
2. 添加上一张 下一张功能
3. 给下边的导航添加点击事件
-->
<div id=wrap>
<ul id=list>
<li><img src=pic/1.jpg/></li>
<li><img src=pic/2.jpg/></li>
<li><img src=pic/3.jpg/></li>
<li><img src=pic/4.jpg/></li>
</ul>
<nav id=navs>
<a href=javascript:; class=active></a>
<a href=javascript:;></a>
<a href=javascript:;></a>
<a href=javascript:;></a>
</nav>
</div>
<script type=text/javascript src=startmove.js></script>
<script type=text/javascript>
(function(){
var wrap = document.queryselector('#wrap');
var list = document.queryselector('#list');
var navs = document.queryselectorall('#navs a');
var wrapw = css(wrap,width);
list.onmousedown = function(e){
clearinterval(list.timer);//清除动画
var startmousex = e.clientx;
var elx = css(list,left);
document.onmousemove = function(e){
var nowmousex = e.clientx;
css(list,left,nowmousex - startmousex + elx);
};
document.onmouseup = function(e){
document.onmousemove = null;
document.onmouseup = null;
var left = css(list,left);
var now = -math.round(left/wrapw); //获取到走了几张图
console.log(now);
now = now<0?0:now;
now = now>navs.length-1?navs.length-1:now;
left = now * wrapw;//计算走到这张图 left需要走的距离
startmove({
el: list,
target: {
left: -left
},
type: easeoutstrong,
time: 800
});
for(var i = 0; i < navs.length; i++){
navs[i].classname = ;
}
navs[now].classname = active;
};
return false;//阻止默认事件(在这的作用阻止图片被选中)
};
})();
</script>
</body>
</html>
以上就是每天一个js 小demo之滑屏幻灯片。主要知识点:event的详细内容。
其它类似信息

推荐信息