很多页面都需要用到界面轮播,但是用原生js相对来说比较复杂,用jQuery实现效果比较迅速,写个简单的demo

1、首先在HTML页面要放置轮播图案位置插入div,这里写了轮播图片数量为3张,所以定义了三个<li>作为轮播button

  <div id= "container">
<p class="ImgList" style="background:url('/img/img1.png') center"></p> <p class="ImgList" style="background:url('img/img2.png') center"></p> <p class="ImgList" style="background:url('/img/img3.png') center"></p>
<!--轮播的按扭-->
<ul class="button">
<li><a class="hover" href="javascript:void(0);">●</a></li>
<li><a href="javascript:void(0);">●</a></li>
<li><a href="javascript:void(0);">●</a></li>
</ul>
</div>

2、为div设置相应的样式

.ImgList {
width: 100%;
height: 420px;
position: absolute;/*绝对定位*/
left: 0px;
top: 0px;
z-index: -1;/*z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面。*/
} .button {
height: 20px;
position: absolute;
right:50%;
bottom: 20px;
z-index:;
display: inline-block; /*行内块级元素*/
}
.button li {
list-style-type: none;
width:20px;
height:10px;
float: left;
margin: 0px 5px;
}
.button li a{
text-decoration: none;
font-size: 30px;
color: #787c82;/*未选中状态颜色*/
} .button li .hover{
color:white;/*设置选中状态为白色*/
}

3、在界面引入jQuery文件(如:jquery-1.7.2.min.js),(注意:文件放在自己的js文件之前)

4、新建js文件,js代码实现轮播效果

 var _index=0;
var timePlay=null;
$("#container .ImgList").eq(0).show().siblings("div").hide();//只显示第一张 $("ul.button li").click(function(){
clearInterval(timePlay);
_index=$(this).index();
$("ul.button li .hover").removeClass('hover');
$(this).find('a').addClass("hover");
$("#container .ImgList").eq(_index).fadeIn().siblings("p").fadeOut();//淡出
autoPlay();
}); //自动轮播
function autoPlay(){
timePlay=setInterval(function(){
_index++;
if(_index<3){
if(_index==2){_index=-1; }
$("ul.button li .hover").removeClass('hover');
$("ul.button li").eq(_index).find('a').addClass("hover"); $("#container .ImgList").eq(_index).fadeIn().siblings("p").fadeOut();
}else{_index=-1;}
},2000);
};
autoPlay();//调用和执行

5、实现效果:

图片自动轮播,间隔时间为2000毫秒,点击相应●时,切换相应图片。

												

JQuery简单实现图片轮播效果的更多相关文章

  1. 使用jQuery做简单的图片轮播效果

      一.本特效主要用到的前端知识点 CSS中绝对定位(absolute)CSS实现垂直居中jQuery中简单的淡入淡出动画效果(fadeIn,fadeOut)定时器(setInterval,clear ...

  2. viewPager+Handler+Timer简单实现广告轮播效果

    基本思想是在Avtivity中放一个ViewPager,然后通过监听去实现联动效果,代码理由详细的解释,我就不说了. MainActivity.java package com.example.adm ...

  3. jQuery个性化图片轮播效果

    jQuery个性化图片轮播效果 购物产品展示:图片轮播器<效果如下所示> 思路说明: 每隔一段时间,实现图片的自动切换及选项卡选中效果,鼠标划入图片动画停止,划出或离开动画开始 两个区域: ...

  4. CSS3图片轮播效果

    原文:CSS3图片轮播效果 在网页中用到图片轮播效果,单纯的隐藏.显示,那再简单不过了,要有动画效果,如果是自己写的话(不用jquery等),可能要费点时间.css3的出现,让动画变得不再是问题,而且 ...

  5. js实现淘宝首页图片轮播效果

    原文:http://ce.sysu.edu.cn/hope2008/Education/ShowArticle.asp?ArticleID=10585 <!DOCTYPE html> &l ...

  6. JQ 实现轮播图(3D旋转图片轮播效果)

    轮播图效果如下: 代码: <!DOCTYPE html> <html xmlns="/www.w3.org/1999/xhtml"> <head> ...

  7. 使用javascript,jquery实现的图片轮播功能

    使用javascript,jquery实现的图片轮播功能本功能采用最基础的javascript和一些简单的jquery技术实现,易理解,以修改使用,代码简易,适合刚开始接触到网站开发的朋友们参考.可以 ...

  8. ios图片轮播效果

    代码地址如下:http://www.demodashi.com/demo/11959.html ImageCarousel 简单封装的图片轮播器 内存过大由于我加载的图片分辨率较高(4k) 文件目录 ...

  9. jQuery轻量级京东图片轮播代码等

    http://sc.chinaz.com/jiaoben/jiaodiantu.html jQuery轻量级京东图片轮播代码   查看全图点击预览 顶(17)踩(4)报错评论(0)下载地址 更新时间: ...

随机推荐

  1. window.showModalDialog以及window.open用法简介

    .可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象.例如:------------------------------parent.htm<script& ...

  2. table 表格隔行换色实现

    table 表格隔行换色实现 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  3. SCJP_104——题目分析(3)

    11. what is reserved words in java?A. run B. default C. implement D. import Java 中,给标识符取名的时候,不能使用关键字 ...

  4. SCJP_104——题目分析(2)

    3. public class IfTest{ public static void main(String args[]){ int x=3; int y=1; if(x=y) System.out ...

  5. KeyPress事件

    在做一个小demo的时候,发现在文本框中输入一个数字,按下“+”,数字增加了,但是“+”仍旧存在的问题,解决方案:提前执行键盘press事件 private void txtNum_KeyPress( ...

  6. Tomcat 9.0安装配置

    本文转自:http://blog.sina.com.cn/s/blog_15126e2170102w5o8.html 一.JDK的安装与配置 1.从官网下载jdk,注意是jdk不是jre.最好从官网下 ...

  7. 使用UIImagePickerController时3DTouch引起Crash

    一.crash的场景 程序中用到UIImagePickerController时,如果在IPhone6S上运行APP,当forceTouch 一个图片时程序会crash,并附带如下crash mess ...

  8. Jedis 一

    //连接Jedis public Jedis getJedis(){ Jedis jedis = new Jedis("192.168.1.12",6379); //权限认证 // ...

  9. KEIL C51的XBYTE关键字

    The XBYTE macro allows you to access individual bytes in the external data memory of the 8051. You m ...

  10. QWidget中嵌入win32 window(使用QWindow和QWidget::createWindowContainer)

    主要用到QWindow::fromWinId和QWidget::createWindowContainer这两个函数 QWindow::fromWinId用来创建一个win32窗口的代理 QWidge ...