使用JQuery实现图片轮播效果的实例(推荐)


Posted in jQuery onOctober 24, 2017

【效果如图】

使用JQuery实现图片轮播效果的实例(推荐)使用JQuery实现图片轮播效果的实例(推荐)使用JQuery实现图片轮播效果的实例(推荐)使用JQuery实现图片轮播效果的实例(推荐)

【原理简述】

这里大概说一下整个流程:

1,将除了第一张以外的图片全部隐藏,

2,获取第一张图片的alt信息显示在信息栏,并添加点击事件

3,为4个按钮添加点击侦听,点击相应的按钮,用fadeOut,fadeIn方法显示图片

4,设置setInterval,定时执行切换函数

【代码说明】

filter(":visible") :获取所有可见的元素

unbind():从匹配的元素中删除绑定的事件

siblings:取得一个包含匹配的元素集合中每一个元素的所有唯一同辈元素的元素集合

【程序源码】

首先引入JS文件:

  <script src="bootstrap/js/jquery-1.11.2.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <link href="bootstrap/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet" type="text/css"/>

HTML部分:

<div id="banner"> 
   <ul>
    <li class="on"><a href="">1</a></li>
    <li><a href="">2</a></li>
    <li><a href="">3</a></li>
    <li><a href="">4</a></li>
    <li><a href="">5</a></li>
    <li><a href="">6</a></li>
   </ul>
   <div id="banner_list">
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_self"><img src="img/a1.jpg" width="280" height="160" /></a>
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_self"><img src="img/a2.jpg" width="280" height="160" /></a>
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_self"><img src="img/a3.jpg" width="280" height="160" /></a>
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_self"><img src="img/a4.jpg" width="280" height="160" /></a>
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_self"><img src="img/a5.jpg" width="280" height="160" /></a>
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_self"><img src="img/a6.jpg" width="280" height="160" /></a>
   </div>
  </div>

CSS部分:

<style type="text/css">
 #banner {position:relative; width:280px; height:160px; border:1px solid #666; overflow:hidden;}
 #banner ul { width:138px; height:18px;position:absolute;list-style-type:none;filter: Alpha(Opacity=80);opacity:0.8;z-index:1002;
    margin:0; padding:0; bottom:3px; right:5px; line-height: 18px; text-align: center;}
 #banner ul li { width: 18px; height: 18px; margin:0px 2px;float:left;display:block;color:#FFF;




 border:#e5eaff 1px solid;background:#6C6D6E;cursor:pointer} 
 #banner ul li.on { background:#900}
 #banner ul li a { color: white;}
 #banner ul li a:hover{text-decoration: none;}
 #banner_list a{position:absolute;} <!-- 让六张图片都可以重叠在一起-->
 #banner_list{position:absolute; right: 5px; bottom: 5px;}
 </style>

JS部分:

<script type="text/javascript">
 var t = n =0, count;
 $(document).ready(function(){ 
  count=$("#banner_list a").length;
  $("#banner_list a:not(:first-child)").hide();
  $("#banner_info").html($("#banner_list a:first-child").find("img").attr('alt'));
  $("#banner_info").click(function(){window.open($("#banner_list a:first-child").attr('href'), "_blank")});
  $("#banner li").click(function() {
   var i = $(this).text() -1;//获取Li元素内的值,即1,2,3,4
   n = i;
   if (i >= count) return;
   $("#banner_info").html($("#banner_list a").eq(i).find("img").attr('alt'));
   $("#banner_info").unbind().click(function(){window.open($("#banner_list a").eq(i).attr('href'), "_blank")})
   $("#banner_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
   document.getElementById("banner").style.background="";
   $(this).toggleClass("on");
   $(this).siblings().removeAttr("class");
  });
  t = setInterval("showAuto()", 4000);
  $("#banner").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 4000);});
 })
 
 function showAuto()
 {
  n = n >=(count -1) ?0 : ++n;
  $("#banner li").eq(n).trigger('click');
 }
 </script>

以上这篇使用JQuery实现图片轮播效果的实例(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

jQuery 相关文章推荐
基于jQuery实现瀑布流页面
Apr 11 jQuery
jquery dataTable 获取某行数据
May 05 jQuery
jQuery自定义多选下拉框效果
Jun 19 jQuery
基于jquery实现多级菜单效果
Jul 25 jQuery
jquery+css实现简单的图片轮播效果
Aug 07 jQuery
jQuery选择器之表单元素选择器详解
Sep 19 jQuery
Vue引入jquery实现平滑滚动到指定位置
May 09 jQuery
用jQuery将JavaScript对象转换为querystring查询字符串的方法
Nov 12 jQuery
JQuery判断radio单选框是否选中并获取值的方法
Jan 17 jQuery
JQuery animate动画应用示例
May 14 jQuery
jQuery编写QQ简易聊天框
Aug 27 jQuery
jQuery实现手风琴特效
Jan 11 jQuery
jquery select插件异步实时搜索实例代码
Oct 20 #jQuery
利用jQuery实现简单的拖曳效果实例代码
Oct 20 #jQuery
jQuery访问浏览器本地存储cookie、localStorage和sessionStorage的基本用法
Oct 20 #jQuery
jQuery实现打开网页自动弹出遮罩层或点击弹出遮罩层功能示例
Oct 19 #jQuery
jQuery实现的粘性滚动导航栏效果实例【附源码下载】
Oct 19 #jQuery
jquery实现图片跟随鼠标的实例
Oct 17 #jQuery
jquery一键控制checkbox全选、反选或全不选
Oct 16 #jQuery
You might like
PHP的autoload自动加载机制使用说明
2010/12/28 PHP
PHP防止表单重复提交的几种常用方法汇总
2014/08/19 PHP
php+mysqli数据库连接的两种方式
2015/01/28 PHP
PHP远程调试之XDEBUG
2015/12/29 PHP
PHP常见数组函数用法小结
2016/03/21 PHP
jQuery使用手册之一
2007/03/24 Javascript
关于viewport,Ext.panel和Ext.form.panel的关系
2009/05/07 Javascript
jquery使用append(content)方法注意事项分享
2014/01/06 Javascript
一个奇葩的最短的 IE 版本判断JS脚本
2014/05/28 Javascript
js自定义回调函数
2015/12/13 Javascript
JavaScript核心语法总结(推荐)
2016/06/02 Javascript
jQuery使用EasyUi实现三级联动下拉框效果
2017/03/08 Javascript
基于ajax和jsonp的原生封装(实例)
2017/10/16 Javascript
javaScript手机号码校验工具类PhoneUtils详解
2017/12/08 Javascript
Node.js使用Angular简单示例
2018/05/11 Javascript
JavaScript插入排序算法原理与实现方法示例
2018/08/06 Javascript
vue+element-ui动态生成多级表头的方法
2018/08/28 Javascript
node.js 如何监视文件变化
2020/09/01 Javascript
python里大整数相乘相关技巧指南
2014/09/12 Python
Python解惑之整数比较详解
2017/04/24 Python
Python部署web开发程序的几种方法
2017/05/05 Python
python利用正则表达式排除集合中字符的功能示例
2017/10/10 Python
Python文件读写常见用法总结
2019/02/22 Python
使用Python快乐学数学Github万星神器Manim简介
2019/08/07 Python
django Model层常用验证器及自定义验证器详解
2020/07/15 Python
CSS3 please 跨浏览器的CSS3产生器
2010/03/14 HTML / CSS
详解使用postMessage解决iframe跨域通信问题
2019/11/01 HTML / CSS
世界上最大的售后摩托车零配件超市:J&P Cycles
2017/12/08 全球购物
美国廉价机票预订网站:Cheapfaremart
2018/04/28 全球购物
捷克厨房用品购物网站:Tescoma
2018/07/13 全球购物
英国在线药房和在线医生:LloydsPharmacy
2019/10/21 全球购物
党员民主生活会对照检查材料思想汇报
2014/09/28 职场文书
小班教师个人总结
2015/02/05 职场文书
财政局个人年终总结
2015/03/03 职场文书
工厂员工辞职信范文
2015/05/12 职场文书
2016元旦主持人经典开场白台词
2015/12/03 职场文书