封装了一个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
投稿
猜你喜欢
- 以下为引用的内容: <html> <head> <title>不刷新页面查询的方法&
- 一、网络请求在uni中可以调用uni.request方法进行请求网络请求需要注意的是:在小程序中网络相关的 API 在使用前需要配置域名白名
- 项目场景:Python版本:3.8因公司业务需求,须开发一套局域网内视频会议软件,此次采用Python实现此功能。程序编写完并在编译器实现此
- 特别是linux系统,装了多个python,有时候找不到python的绝对路径,有时候装了个django,又找不到django安装到哪里了。
- 调用python自带的GUI制作库一开始想用Tkinter制作GUI的,网上说是python自带的,结果输入:import tkinter后
- 数据API数据集方法不会修改数据集,而是创建新数据集。可通过调用 map() 方法将转换应用于每个元素:dataset = dataset.
- 此程序主要是针对某个目录下的全部文件进行筛选,会删除重复的文件。原理很简单,会计算每个文件的哈希,将哈希存入一个字典,文件名对应哈希。imp
- 写在前面的话作为有个 Python 菜逼,之前一直用的 Pycharm,但是在主题这一块怎么调整都感觉要么太骚,看起来不舒服,要么就是简直不
- 环境安装安装Anaconda,官网链接Anaconda使用conda创建py3.6的虚拟环境,并激活使用conda create -n py
- 比较说明1、break和continue是python两个关键字2、break和continue只能用在循环中3、break是终止循环的执行
- 作者:JavaScript Kit译者:子乌(Sheneyan)翻译日期:2006-02-12英文原文:Conditional Compil
- 我试了网上提供的一些方法都不行,最后还是自己用SQL解决了些问题。 1 在查询分析器里面选中出问题的数据库,然后输入: Exec sp_co
- Rex 是 Perl 编写的基于 SSH 链接的集群配置管理系统,语法上类似 Puppet DSL。官网中文版见 http://rex.pe
- 前言本文主要给大家介绍了关于微信小程序自定义导航的相关内容,详细代码请见github,请点击地址 (本地下载),其中有原生小程序的
- 本文介绍了python OpenCV学习笔记之直方图均衡化,分享给大家,具体如下:官方文档 – https://docs.opencv.or
- 引言python编程时,一部分人习惯将实现同一个功能的代码放在同一个文件;使用这些代码只需要import就可以了;下面看一个例子。testM
- 我们使用的是QWebview模块,这里也主要是展示下QWebview的用法。之前在网上找了半天的解析网页的内容,都不是很清楚。这是核心代码:
- 在运用xmlhttp组件编写程序中,会碰到 "msxml3.dll 错误 ‘800c0005’&nb
- 生活形态(Life-Style)的概念源自社会学与心理学,六十年代即有学者正式引用到市场营销领域,并运用其心理影射与多维度等特质,着力解释人
- 错误代码如下:NotFoundError (see above for traceback): Unsuccessful TensorSli