欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

封装了一个js图片轮换效果的函数

时间:2021-02-12 08:52:21|栏目:JavaScript代码|点击:
其中如果有问题,有更好的意见或者建议都可在最后留言,都将对您感激不尽。
具体的代码如下:
复制代码 代码如下:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<title>图片轮换效果</title>
<style type="text/css">
body, div { margin: 0; paading: 0; font-size: 12px; }
ul, li { margin: 0; padding: 0; list-style: none; }
.clear { clear: both; width: 1px; height: 0px; line-height: 0px; font-size: 1px; }
.left { float: left; }
.right { float: right; }
ul, li { margin: 0; padding: 0; list-style: none; }
.box { width: 960px; margin: 0 auto; padding-top: 15px; }
.flash { position: relative; width: 360px; height: 280px; overflow: hidden; }
.list { position: relative; width: 360px; height: 260px; overflow: hidden; }
.list li img{ position: absolute; left: 0; top: 0; width: 360px; height: 260px;}
.list li { display: none; }
.list .over { display: block;}
.btn { position: absolute; top: 233px; width: 360px; height: 26px; background: #000; line-height: 26px; opacity: 0.7; filter: alpha(opacity=70); text-align: right; }
.btn a { padding: 2px 5px; margin: 0 2px; border: 1px solid #fff; border-radius: 2px; background: #000; color: #fff; text-decoration: none; cursor: pointer; }
.btn .over { background: #f00; }
.btn2 { position: absolute; top: 206px; height:62px; }
.btn2 img { width: 70px; height: 60px; border: 1px solid #ccc; }
.btn2 .over img { border: 1px solid #f00; }
.flash2 { position: relative; width: 800px; }
.flash2 .list { float: left; }
.flash2 .btn2 { float: left; position: static; width: 150px; height: 280px; }
.flash2 .btn2 img { width: 120px; height: 47px; }
</style>
<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="scroll.js">
var autoPlay = {
setTimeShow: function(showObj, btnObj, showClass, timer) {
var length = btnObj.length;
var timeId = null;
var index = 0;
if(showObj.length == btnObj.length) {
timeId = window.setInterval(function(){
index = autoPlay.showCon(showObj, btnObj, showClass, index); //返回操作后的index
}, timer);
} else if (length == 1) {
clearInterval(timeId); // 如果只有一张图片,则清除计时器,停止自动播放。
} else {
return false;
}
// 鼠标点击的操作。
btnObj.each(function(i) {
$(this).click(function() {
$(this).addClass(showClass);
btnObj.not($(this)).removeClass(showClass);
showObj.eq(i).show('slow');
showObj.not(showObj.eq(i)).hide();
index = i;
});
});
},
//自动轮换显示
showCon: function(show, btnObj, showClass, index) {
btnObj.eq(index).addClass(showClass);
btnObj.not(btnObj.eq(index)).removeClass(showClass);
show.eq(index).show('slow');
show.not(show.eq(index)).hide();
if (index >= btnObj.length -1) {
index = 0;
} else {
index++;
}
return index; //返回操作后的index
},
};
</script>
<script type="text/javascript">
$(document).ready(function() {
autoPlay.setTimeShow($('#list1 li'), $('#btn1 a'), 'over', 3000);
autoPlay.setTimeShow($('#list2 li'), $('#btn2 a'), 'over', 3000);
autoPlay.setTimeShow($('#list3 li'), $('#btn3 a'), 'over', 3000);
});
</script>
</head>
<body>
<div class="box">
<div class="flash">
<ul class="list" id='list1'>
<li class="over"><img src="images/11.jpg" /></li>
<li><img src="images/2.jpg" /></li>
<li><img src="images/6.jpg" /></li>
<li><img src="images/8.jpg" /></li>
<li><img src="images/9.jpg" /></li>
</ul>
<div class="btn" id="btn1">
<a class="over" href="#">1</a><a href="#">2</a><a href="#">3</a><a href="#">4</a><a href="#">5</a>
</div>
</div>
</div>
<div class="box">
<div class="flash">
<ul class="list" id='list2'>
<li class="over"><img src="images/11.jpg" /></li>
<li><img src="images/2.jpg" /></li>
<li><img src="images/6.jpg" /></li>
<li><img src="images/8.jpg" /></li>
<li><img src="images/9.jpg" /></li>
</ul>
<div class="btn2" id="btn2">
<a class="over" href="#"><img src="images/11.jpg"/></a><a href="#"><img src="images/2.jpg"/></a><a href="#"><img src="images/6.jpg"/></a><a href="#"><img src="images/8.jpg"/></a><a href="#"><img src="images/9.jpg"/></a>
</div>
</div>
</div>
<div class="box">
<div class="flash2">
<ul class="list" id='list3'>
<li class="over"><img src="images/11.jpg" /></li>
<li><img src="images/2.jpg" /></li>
<li><img src="images/6.jpg" /></li>
<li><img src="images/8.jpg" /></li>
<li><img src="images/9.jpg" /></li>
</ul>
<div class="btn2" id="btn3">
<a class="over" href="#"><img src="images/11.jpg"/></a><a href="#"><img src="images/2.jpg"/></a><a href="#"><img src="images/6.jpg"/></a><a href="#"><img src="images/8.jpg"/></a><a href="#"><img src="images/9.jpg"/></a>
</div>
</div>
</div>
</body>
</html>

上一篇:javascript IFrame 强制刷新代码

栏    目:JavaScript代码

下一篇:Js保留小数点的4种效果实现代码分享

本文标题:封装了一个js图片轮换效果的函数

本文地址:http://www.codeinn.net/misctech/61897.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有