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

时间:2024-06-21 20:21:48 

其中如果有问题,有更好的意见或者建议都可在最后留言,都将对您感激不尽。
具体的代码如下:


<!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>
标签:图片轮换
0
投稿

猜你喜欢

  • javascript让浏览器实现复读机的功能

    2008-10-10 11:49:00
  • javascript学习总结之js使用技巧

    2024-04-18 10:59:16
  • JS仿iGoogle自定义首页模块拖拽特效的方法

    2024-04-22 22:36:37
  • python 如何引入协程和原理分析

    2022-09-06 11:26:07
  • sql中返回参数的值

    2024-01-29 11:29:00
  • Orcale权限、角色查看创建方法

    2024-01-20 04:22:02
  • Python实现RLE格式与PNG格式互转

    2021-07-11 18:23:19
  • MySQL 索引和数据表该如何维护

    2024-01-26 18:35:16
  • 在CentOS上MySQL数据库服务器配置方法

    2024-01-19 07:01:21
  • Yii框架学习笔记之应用组件操作示例

    2024-05-11 09:23:07
  • go如何利用orm简单实现接口分布式锁

    2023-06-17 16:55:04
  • JS打开新窗口的2种方式

    2023-07-07 02:44:49
  • Vite引入虚拟文件的实现

    2024-05-21 10:30:54
  • 深入理解vue中的slot与slot-scope

    2024-05-05 09:07:18
  • 在Docker上部署Python的Flask框架的教程

    2023-03-27 02:55:38
  • Pycharm安装第三方库时Non-zero exit code错误解决办法

    2023-03-15 12:15:01
  • Python生成器传参数及返回值原理解析

    2022-03-17 08:58:40
  • python opencv实现目标区域裁剪功能

    2022-07-15 19:17:56
  • vue单页应用中如何使用jquery的方法示例

    2024-05-09 10:40:14
  • Python简洁优雅的推导式示例详解

    2022-06-26 11:52:20
  • asp之家 网络编程 m.aspxhome.com