jQuery焦点轮播图
来源:互联网 发布:弹力牛仔裤男 知乎 编辑:程序博客网 时间:2024/06/03 10:22
<!DOCTYPE HTML><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> <title></title> <script type="text/javascript"> $(document).ready(function() { var imgsrollLength = $("#imgsroll li").length;//3 var index = 0; var t;//定时器 var srollTime = 3000;//图片轮播时间 //图片隐藏消失 function animate(index){ $("#imgsroll li").animate({ opacity:0 }); $("#imgsroll li").eq(index).animate({ opacity:1 }); } //圆点显示 function showButtons(index){ $("#point li").removeClass("on") $("#point li").eq(index).addClass("on"); } //圆点点击显示 $("#point li").each(function(){ $(this).click(function(){ //点击当前的按钮时不运行下面的代码 if(this.className=="on"){ return false; } showButtons($(this).index()); animate($(this).index()); }) }) //自动运行 function srollAuto(){ t = setTimeout(function(){ $("#next").click(); srollAuto() },srollTime) } srollAuto(); //停止自动 function srollStop(){ clearTimeout(t) } //鼠标移入移出事件 $("#banner").mouseover(function(){ srollStop(); $("button").show(); }) $("#banner").mouseout(function(){ $("button").hide(); srollAuto() }) //方向按钮点击事件 $("#next").click(function(){ index++; if(index==imgsrollLength){ index = 0; } animate(index) showButtons(index); }) $("#prev").click(function(){ index--; if(index<0){ index = imgsrollLength-1; } animate(index); showButtons(index); }) }) </script> </head> <style> * {list-style: none;padding: 0;margin: 0} #banner{width:640px;overflow: hidden;height:350px;position: relative;cursor: pointer;} #imgsroll{width:3000px;height:350px;position: absolute;} #imgsroll li{float:left;position: absolute;opacity: 0;} #imgsroll li.on{opacity: 1;} #point{position: absolute;bottom:20px;left:50px;} #point li{width:20px;height:20px;border-radius: 50%;background: #333;float:left;margin-right: 10px;} #point li.on{background: red;} button{position: absolute;bottom:180px;z-index:99;font-size: 40px;color:#ebebeb;background: transparent;border:none;cursor: pointer;display: none;} #prev{left:0} #next{right:0} </style> <body> <div id="banner"> <ul id="imgsroll"> <li class="on"><img src="001.jpg" /></li> <li><img src="002.jpg" alt="" /></li> <li><img src="003.jpg" alt="" /></li> </ul> <ul id="point"> <li class="on"></li> <li></li> <li></li> </ul> <button id="prev"><</button> <button id="next">></button> </div> </body></html>
一、方向按钮点击,根据改变index参数的值,把参数传入到animate函数中,实现图片的变化,并且控制index的范围,实现图片无限滚动
二、添加圆点显示隐藏的事件showButtons函数,并且绑定到方向点击事件上,将方向点击的函数中的index参数传入showButtons函数中
三、给圆点遍历,添加点击事件,点击当前某一个圆点时,可以通过$(this).index()获取当前点击的这个圆点的顺序值,然后将这个顺序值作为参数,分别传入animate函数和showButtons函数中。
四、添加自动轮播事件,停止轮播事件,鼠标移入移出事件。
阅读全文
0 0
- jQuery焦点轮播图
- Jquery焦点与失去焦点
- jQuery焦点图
- jquery 设置焦点
- jquery焦点事件
- JQUERY焦点设置
- jquery dialog 获取焦点
- Jquery焦点图实例
- jQuery设置文本焦点
- jquery失去焦点事件
- 焦点图效果 【jquery】
- JQuery焦点图
- jquery获取焦点事件
- Jquery 获取焦点,和失去焦点
- jquery 获得焦点与失去焦点插件
- input失去焦点和获得焦点jquery焦点事件
- input失去焦点和获得焦点jquery焦点事件插件
- input失去焦点和获得焦点jquery焦点事件
- NOIP2012普及组-寻宝
- hdu 6115 Factory(lca暴力)
- 背包问题 01背包 完全背包 多重背包
- CSI(channel state information)目标识别和室内定位
- 修改mysql提示符
- jQuery焦点轮播图
- Goldbach`s Conjecture LightOJ
- HDU 1257 最少拦截系统 (贪心)
- 摄像头分类 之 结构光 kinect
- hadoop系列之一服务启动以及结果查看
- B
- Android 中 C++ Thread线程用法
- hrbust1328 (欧几里得)
- 游戏理论之Shapley Value(Shapley值)