使用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编写textarea输入字数限制代码
Mar 23 jQuery
jquery submit()不能提交表单的解决方法
Apr 24 jQuery
解决jQuery ajax动态新增节点无法触发点击事件的问题
May 24 jQuery
Django中使用jquery的ajax进行数据交互的实例代码
Oct 15 jQuery
jQuery实现简单的回到顶部totop功能示例
Oct 16 jQuery
jQuery Validate插件ajax方式验证输入值的实例
Dec 21 jQuery
jQuery实现仿京东防抖动菜单效果示例
Jul 06 jQuery
jQuery实现的点击按钮改变样式功能示例
Jul 21 jQuery
jQuery扩展方法实现Form表单与Json互相转换的实例代码
Sep 05 jQuery
jQuery实现移动端下拉展现新的内容回弹动画
Jun 24 jQuery
jQuery实现异步上传一个或多个文件
Aug 17 jQuery
jQuery实现tab栏切换效果
Dec 22 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
Thinkphp实现MySQL读写分离操作示例
2014/06/25 PHP
取得传值的函数
2006/10/27 Javascript
Jquery替换已存在于element上的event的方法
2010/03/09 Javascript
Jquery 获取对象的几种方式介绍
2014/01/17 Javascript
JavaScript DOM节点添加示例
2014/07/16 Javascript
jQuery中attr()方法用法实例
2015/01/05 Javascript
jQuery的基本概念与高级编程
2015/05/14 Javascript
js跨域资源共享 基础篇
2016/07/02 Javascript
nodeJs内存泄漏问题详解
2016/09/05 NodeJs
JS常见简单正则表达式验证功能小结【手机,地址,企业税号,金额,身份证等】
2017/01/22 Javascript
vue如何获取点击事件源的方法
2017/08/10 Javascript
Node.js上传文件功能之服务端如何获取文件上传进度
2018/02/05 Javascript
解决vue项目报错webpackJsonp is not defined问题
2018/03/14 Javascript
JS的函数调用栈stack size的计算方法
2018/06/24 Javascript
解决vue axios跨域 Request Method: OPTIONS问题(预检请求)
2020/08/14 Javascript
VUE Elemen-ui之穿梭框使用方法详解
2021/01/19 Javascript
Vertx基于EventBus发送接受自定义对象
2020/11/16 Javascript
Python运行的17个时新手常见错误小结
2012/08/07 Python
Python3之简单搭建自带服务器的实例讲解
2018/06/04 Python
python文档字符串(函数使用说明)使用详解
2019/07/30 Python
Python实现手机号自动判断男女性别(实例解析)
2019/12/22 Python
Django模型验证器介绍与源码分析
2020/09/08 Python
CSS3 please 跨浏览器的CSS3产生器
2010/03/14 HTML / CSS
CSS3制作Dropdown下拉菜单的方法
2015/07/18 HTML / CSS
Blancsom美国/加拿大:服装和生活用品供应商
2018/07/27 全球购物
美国转售二手商品的电子商务平台:BLINQ
2018/12/13 全球购物
波兰在线体育用品商店:Hop-Sport.pl
2019/07/23 全球购物
商铺租赁意向书
2014/04/01 职场文书
城管执法人员个人对照检查材料思想汇报
2014/09/29 职场文书
2014年销售工作总结与计划
2014/12/01 职场文书
2014年政协工作总结
2014/12/09 职场文书
2015年见习期工作总结
2014/12/12 职场文书
教师廉洁自律个人总结
2015/02/10 职场文书
个人专业技术总结
2015/03/05 职场文书
听课评课活动心得体会
2016/01/15 职场文书
使用feign服务调用添加Header参数
2021/06/23 Java/Android