直接可以用,网上摘下来的!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS图片轮播特效-左右切换</title> <style type="text/css">
.imageRotation{
height:270px;
width:570px;
overflow:hidden; /*--超出容器的所有元素都不可见--*/
position:relative; /*--相对定位--*/
border:10px solid #eee;
bodrer-radius:5px;
-webkit-border-radius:5px;
-moz-border-radius:5px;
}
/*-------------图片容器---------------*/
.imageBox{
position:absolute; /*--固定定位--*/
height:270px;
top:0px;
left:0px;
overflow:hidden;
}
.imageBox img {
display:block;
height:270px;
width:570px;
float:left;
border:none;
}
/*-------------标题容器---------------*/
.titleBox{
position:absolute;
bottom:0px;
width:570px;
height:40px;
overflow:hidden;
}
.titleBox p{
position:absolute;
bottom:-40px;
width:550px;
height:40px;
margin:0px;
padding:0px 10px;
line-height:40px;
z-index:1;
border-top:1px solid #000;
background-color:#000;
color:#fff;
font-family:"微软雅黑","yahei";
opacity:0.5;
-moz-opacity:0.5;
-webkit-opacity:0.5;
filter:alpha(opacity=50);
}
.titleBox p span{
opacity:1;
-moz-opacity:1;
-webkit-opacity:1;
filter:alpha(opacity=100);
}
.titleBox p.active{
bottom:0px;
}
/*-------------图标容器---------------*/
.icoBox{
position:absolute; /*--固定定位--*/
bottom:14px;
right:15px;
width:76px;
height:12px;
text-align:center;
line-height:40px;
z-index:2;
}
.icoBox span{
display:block;
float:left;
height:12px;
width:12px;
margin-left:3px;
overflow:hidden;
background:url("images/ico.png") 0px 0px no-repeat;
cursor:pointer;
}
.icoBox span.active {
background-position:0px -12px;
cursor:default;
}
</style>
</head>
<body>
<div class="imageRotation">
<div class="imageBox">
<a href="http://www.itxueyuan.org" target="_blank"><img src="data:images/1.jpg" /></a>
<a href="http://www.itxueyuan.org" target="_blank"><img src="data:images/2.jpg" /></a>
<a href="http://www.itxueyuan.org" target="_blank"><img src="data:images/3.jpg" /></a>
<a href="http://www.itxueyuan.org" target="_blank"><img src="data:images/4.jpg" /></a>
<a href="http://www.itxueyuan.org" target="_blank"><img src="data:images/5.jpg" /></a>
</div>
<div class="titleBox">
<p class="active"><span>第一张图片标题</span></p>
<p>第二张图片标题</p>
<p>第三张图片标</p>
<p>第四张图片标题</p>
<p>第五张图片标题</p>
</div>
<div class="icoBox">
<span class="active" rel="1">1</span>
<span rel="2">2</span>
<span rel="3">3</span>
<span rel="4">4</span>
<span rel="5">5</span>
</div>
</div> <script type="text/javascript" src="http://www.itxueyuan.org/uploads/javascript/jquery.js"></script>
<script type="text/javascript"> $(document).ready(function() {
$(".imageRotation").each(function(){
// 获取有关参数
var imageRotation = this, // 图片轮换容器
imageBox = $(imageRotation).children(".imageBox")[0], // 图片容器
titleBox = $(imageRotation).children(".titleBox")[0], // 标题容器
titleArr = $(titleBox).children(), // 所有标题(数组)
icoBox = $(imageRotation).children(".icoBox")[0], // 图标容器
icoArr = $(icoBox).children(), // 所有图标(数组)
imageWidth = $(imageRotation).width(), // 图片宽度
imageNum = $(imageBox).children().size(), // 图片数量
imageReelWidth = imageWidth*imageNum, // 图片容器宽度
activeID = parseInt($($(icoBox).children(".active")[0]).attr("rel")), // 当前图片ID
nextID = 0, // 下张图片ID
setIntervalID, // setInterval() 函数ID
intervalTime = 4000, // 间隔时间
imageSpeed =500, // 图片动画执行速度
titleSpeed =250; // 标题动画执行速度
// 设置 图片容器 的宽度
$(imageBox).css({'width' : imageReelWidth + "px"});
// 图片轮换函数
var rotate=function(clickID){
if(clickID){ nextID = clickID; }
else{ nextID=activeID<=4 ? activeID+1 : 1; }
// 交换图标
$(icoArr[activeID-1]).removeClass("active");
$(icoArr[nextID-1]).addClass("active");
// 交换标题
$(titleArr[activeID-1]).animate(
{bottom:"-40px"},
titleSpeed,
function(){
$(titleArr[nextID-1]).animate({bottom:"0px"} , titleSpeed);
}
);
// 交换图片
$(imageBox).animate({left:"-"+(nextID-1)*imageWidth+"px"} , imageSpeed);
// 交换IP
activeID = nextID;
}
setIntervalID=setInterval(rotate,intervalTime);
$(imageBox).hover(
function(){ clearInterval(setIntervalID); },
function(){ setIntervalID=setInterval(rotate,intervalTime); }
);
$(icoArr).click(function(){
clearInterval(setIntervalID);
var clickID = parseInt($(this).attr("rel"));
rotate(clickID);
setIntervalID=setInterval(rotate,intervalTime);
});
});
});
</script> </body>
</html>

JS图片轮播[左右轮播的更多相关文章

  1. JS图片自动和可控的轮播切换特效

    点击这里查看效果:http://hovertree.com/texiao/js/1.htm HTML文件代码如下: <!DOCTYPE html> <html xmlns=" ...

  2. 分别用css3、JS实现图片简单的无缝轮播功效

    本文主要介绍分别使用CSS3.JS实现图片简单无缝轮播功效: 一.使用CSS3实现:利用animation属性 (实现一张一张的轮播,肉眼只看见一张图片) HTML部分比较简单,两个div下包着几个i ...

  3. js图片轮播效果实现代码

    首先给大家看一看js图片轮播效果,如下图 具体思路: 一.页面加载.获取整个容器.所有放数字索引的li及放图片列表的ul.定义放定时器的变量.存放当前索引的变量index 二.添加定时器,每隔2秒钟i ...

  4. js 图片轮播简单版

    <html> <head> <meta charset="utf-8" /> <title></title> <s ...

  5. JS封装动画框架,网易轮播图,旋转轮播图

    JS封装动画框架,网易轮播图,旋转轮播图 1. JS封装运动框架 // 多个属性运动框架 添加回调函数 function animate(obj,json,fn) { clearInterval(ob ...

  6. js 实现淘宝无缝轮播图效果,可更改配置参数 带完整版解析代码[slider.js]

    前言:         本人纯小白一个,有很多地方理解的没有各位大牛那么透彻,如有错误,请各位大牛指出斧正!小弟感激不尽.         本篇文章为您分析一下原生JS写淘宝无缝轮播图效果 需求分析: ...

  7. 原生js面向对象编程-选项卡(自动轮播)

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. JS图片Switchable切换大集合

    JS图片切换大集合 利用周末2天把JS图片切换常见效果封装了下,比如:轮播,显示隐藏,淡入淡出等.废话不多说,直接看效果吧!JSFiddler链接如下: 想看JS轮播切换效果请点击我! 当然由于上传图 ...

  9. 支持无限加载的js图片画廊插件

    natural-gallery-js是一款支持无限加载的js图片画廊插件.该js图片画廊支持图片的懒加载,可以对图片进行搜索,分类,还可以以轮播图的方式来展示和切换图片. 使用方法 在页面中引入下面的 ...

随机推荐

  1. tomcat建立双向https安全连接

    参考:http://www.hangge.com/blog/cache/detail_992.htmltomcat连接器的框架是coyote,有关信息参考:http://blog.csdn.net/w ...

  2. laravel where orwhere的写法

    orWhere如果不用闭包的形式写很容易写成分开的查询条件 要写成一组查询条件需要这样闭包写(就相当于把这两个条件放在一个小括号里,是一组查询条件“(xxx or xxx)”): if (!empty ...

  3. docker-compose快速部署环境笔记

    # 在含有 docker-compose.yml 的文件夹下 构建容器# 如有使用 Dockerfile 在修改 Dockerfile 文件之后再次执行如下即可应用修改docker-compose u ...

  4. Git代码行数统计命令

    统计zhangsan在某个时间段内的git新增删除代码行数 git log --author=zhangsan--since=2018-01-01 --until=2019-04-01 --forma ...

  5. iOS上传图片问题

    今天一定得写一篇博客,有以下原因: 1>第一次做图片上传的功能,算是一种记录吧; 2>在这个问题上,纠结,迷茫了很久,主要还是被后台坑了; 1.上传图片的方法是用的AFNetWorking ...

  6. python配置主机名

    .准备hosts模板 mkdir -p /k8s/profile cat >/k8s/profile/hosts<<EOF 192.168.0.91 test1 192.168.0. ...

  7. C基础知识(2):变量&常量的定义和声明

    变量定义和声明 (1) 使用int,char等类型符定义变量 使用int,char等类型符定义变量时,不管有没有指定初始值,都就已经建立了存储空间(开辟内存).内存寻址由大到小,优先分配内存地址比较大 ...

  8. linux新建文件夹

    mkdir -p .... -p  ----parents no error if existion, make parent directories as needed

  9. 关于JavaScript实例化的理解

    要理解这个,我们首先要理解一个概念“类”,所谓类,指的是对象的模版.对象就是类的实例.由前面我们知道,对象是单个实物的抽象,所以通常需要一个模版,表示某一类实物的共同特征,然后对象根据这个模版生成,这 ...

  10. Tensorflow 多层全连接神经网络

    本节涉及: 身份证问题 单层网络的模型 多层全连接神经网络 激活函数 tanh 身份证问题新模型的代码实现 模型的优化 一.身份证问题 身份证号码是18位的数字[此处暂不考虑字母的情况],身份证倒数第 ...