<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>带渐变与滑动的图片展示</title>
<style>
ul{ margin:0; padding-left:0;}
li{ list-style:none;}
img{ border:none;}
#main{ width:280px; height:330px; overflow:hidden; position:relative; margin:20px auto 0 auto;}
#main ul{ position:absolute; left:0;}
#main ul li{ width:280px; height:330px; float:left; position:absolute; filter:alpha(opacity=0); opacity:0;}
#btn{ line-height:13px; text-align:center; background:#eeeeee; width:280px; margin:10px auto 0 auto;}
#btn a{ display:inline-block; background:url(img.gif) no-repeat; width:13px; height:13px;}
#btn a.index{ background-position:-13px 0;}
#btn a.active{ background-position:-26px 0;}
#btn a.prev{ background-position:0 0;}
#btn a.next{ background-position:-39px 0;}
</style>
<script type="text/javascript" src="miaov.js"></script>
<script>
window.onload = function(){
var oMain = document.getElementById('main');
var oUl = oMain.getElementsByTagName('ul')[0];
var aLi = oUl.getElementsByTagName('li');
var oBtn = document.getElementById('btn');
var aA = oBtn.getElementsByTagName('a');
var iNow = 1;
var iNow2 = 1;
var bBtn = true;
var num = 3;
var timer = null;
oUl.style.width = aLi.length * aLi[0].offsetWidth + 'px';
aA[0].onclick = function(){
if(bBtn){
clearInterval(timer);
timer = setInterval(autoPlay,3000);
for(var i=0;i<aLi.length;i++){
aLi[i].style.position = 'relative';
aLi[i].style.filter = 'alpha(opacity=100)';
aLi[i].style.opacity = 1;
}
oUl.style.left = -(iNow-1)*aLi[0].offsetWidth + 'px';
if(iNow==1){
iNow = aLi.length;
aLi[aLi.length-1].style.position = 'relative';
aLi[aLi.length-1].style.left = -aLi.length * aLi[0].offsetWidth + 'px';
}
else{
iNow--;
}
iNow2--;
toRun();
bBtn = false;
}
};
aA[aA.length-1].onclick = function(){
if(bBtn){
clearInterval(timer);
timer = setInterval(autoPlay,3000);
for(var i=0;i<aLi.length;i++){
aLi[i].style.position = 'relative';
aLi[i].style.filter = 'alpha(opacity=100)';
aLi[i].style.opacity = 1;
}
oUl.style.left = -(iNow-1)*aLi[0].offsetWidth + 'px';
if(iNow==aLi.length){
iNow = 1;
aLi[0].style.position = 'relative';
aLi[0].style.left = aLi.length * aLi[0].offsetWidth + 'px';
}
else{
iNow++;
}
iNow2++;
toRun();
bBtn = false;
}
};
for(var i=1;i<aA.length-1;i++){
aA[i].index = i;
aA[i].onclick = function(){
clearInterval(timer);
timer = setInterval(autoPlay,3000);
iNow = this.index;
iNow2 = this.index;
toShow();
};
}
function toRun(){
for(var i=1;i<aA.length-1;i++){
aA[i].className = 'index';
}
aA[iNow].className = 'active';
startMove(oUl,{left:-(iNow2-1)*aLi[0].offsetWidth},function(){
if(iNow==1){
aLi[0].style.position = 'relative';
aLi[0].style.left = 0;
oUl.style.left = 0;
iNow2 = 1;
}
else if(iNow==aLi.length){
aLi[aLi.length-1].style.position = 'relative';
aLi[aLi.length-1].style.left = 0;
oUl.style.left = -(aLi.length-1)*aLi[0].offsetWidth + 'px';
iNow2 = aLi.length;
}
for(var i=0;i<aLi.length;i++){
aLi[i].style.position = 'absolute';
aLi[i].style.filter = 'alpha(opacity=0)';
aLi[i].style.opacity = 0;
}
oUl.style.left = 0;
aLi[iNow2-1].style.zIndex = num++;
aLi[iNow2-1].style.filter = 'alpha(opacity=100)';
aLi[iNow2-1].style.opacity = 1;
bBtn = true;
});
}
function toShow(){
for(var i=1;i<aA.length-1;i++){
aA[i].className = 'index';
}
for(var i=0;i<aLi.length;i++){
startMove(aLi[i],{opacity:0});
}
aA[iNow].className = 'active';
startMove(aLi[iNow-1],{opacity:100},function(){
aLi[iNow-1].style.zIndex = num++;
});
}
timer = setInterval(autoPlay,3000);
function autoPlay(){
if(iNow==aLi.length){
iNow = 1;
iNow2 = 1;
}
else{
iNow++;
iNow2++;
}
toShow();
}
};
</script>
</head>
<body>
<div id="main">
<ul>
<li style="z-index:2; filter:alpha(opacity=100); opacity:1;"><a href="#"><img src="1.jpg" /></a></li>
<li><a href="#"><img src="2.jpg" /></a></li>
<li><a href="#"><img src="3.jpg" /></a></li>
<li><a href="#"><img src="4.jpg" /></a></li>
</ul>
</div>
<div id="btn">
<a class="prev" href="javascript:;"></a>
<a class="active" href="javascript:;"></a>
<a class="index" href="javascript:;"></a>
<a class="index" href="javascript:;"></a>
<a class="index" href="javascript:;"></a>
<a class="next" href="javascript:;"></a>
</div>
</body>
</html>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
原生js焦点图滑动切换图片展示代码.zip (7个子文件)
新建文件夹
2.jpg 37KB
img.gif 551B
1.jpg 48KB
miaov.js 1KB
demo.html 5KB
3.jpg 27KB
4.jpg 29KB
共 7 条
- 1
资源评论
小徐博客
- 粉丝: 1968
- 资源: 1622
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功