淡入淡出轮播(banner),自动按图片个数生成居中按钮——和派孔明
2016-06-16 15:04
423 查看
淡入淡出轮播(banner),自动按图片个数生成居中按钮
/*1、JQuery带左右按钮淡入淡出轮播
2、轮播图根据图片数量自动生成按钮个数
3、在宽高不确定的情况下,居中元素
注:不管是菜鸟还是大神,若有bug,及时联系交流,QQ 2766588380;
闻道有先后,术业有专攻,所有的大神都是从菜鸟的道路上走出来的
*/
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>淡入淡出轮播,banner</title> <style> *{margin:0;padding:0;} .box{width:1290px;height:410px;overflow:hidden;position:relative;margin:30px auto;} .box .banner{width:1290px;height:410px;margin:0 auto;overflow:hidden;position:relative;} .box .banner img{width:1290px;height:410px;position:absolute;left:0;top:0;opacity:0;filter: alpha(opacity=0);} .box .prev{width:35px;height:57px;position:absolute;left:0;top:50%;margin-top:-27px;background:#ccc;z-index:10;font-size:70px;line-height:57px;text-align: center;text-decoration:none;color:#fff;display:none;opacity:0.5;} .box .next{width:35px;height:57px;position:absolute;right:0;top:50%;margin-top:-27px;background:#ccc;z-index:10;font-size:70px;line-height:57px;text-align: center;text-decoration:none;color:#fff;display:none;opacity:0.5;} .box:hover .prev{display:block;} .box:hover .next{display:block;} .box .page{/*width:130px;*/position:relative;float:left;bottom:40px;left:50%; } .box .page a{position:relative; left:-50%;display:inline-block;width:22px;height:22px;background-color:#666;margin: 0px 10px;float:left;color:#fff;text-decoration:none;text-align: center;border-radius:50%;cursor: pointer;} .box .page a.active{background-color:red;} </style> <script src="jquery-1.7.2.js" type="text/javascript"></script> <script> $(function(){ var aPage = $(".box .page a"); var aImg = $(".box .banner img"); var iSize = $(".box .banner img").size(); var index = 0; // 按照图片的多少自动生成点击按钮个数 (function(){ for (var i = 1; i <=aImg.length; i++) { var allA = $("<a class='a'>"+i+"</a>"); $("#page").append(allA); $("#page a").first().addClass('active'); }; //分页按钮点击 $(".box").on("click",".a",function(){ var _this = $(this).text() - 1; change(_this); }); })(); //左按钮 $("#prev").click(function() { index--; if (index==-1) { index=iSize-1; } change(index); }); //右按钮 $("#next").click(function() { index++; if (index==iSize) { index=0; } change(index); }); //封装切换函数 function change(index){ $(".a").eq(index).addClass('active').siblings().removeClass('active'); aImg.stop().eq(index).animate({opacity:1}, 1000).siblings().animate({opacity:0}, 1000); }; //自动 function autoshow(){ index++; if (index<iSize-1) { change(index); }else{ index=0; change(index); } } //鼠标移入显示,移除隐藏左右按钮 $(".box").mouseover(function() { clearInterval(timer); }).mouseout(function(event) { timer=setInterval(autoshow,3000); }).trigger('mouseout'); }) </script> </head> <body> <div class="box"> <a id="prev" class="prev" href="javascript:;"><</a> <a id="next" class="next" href="javascript:;">></a> <div class="banner" id="banner"> <img style="opacity:1;filter:alpha(opacity=100);" src="images/banner1.png" alt=""> <img src="images/banner2.png" alt=""> <img src="images/banner3.png" alt=""> <img src="images/banner4.png" alt=""> <img src="images/banner3.png" alt=""> </div> <div class="page" id="page"> <!--________________________________________________ --> <!-- <a class="active" href="javascript:;">1</a> <a href="javascript:;">2</a> <a href="javascript:;">3</a> --> <!--________________________________________________ --> </div> </div> </body> </html>
http://blog.csdn.net/xyphf/article/details/51690506 宽高不确定的div居中方法
相关文章推荐
- android app开发遇到的一些问题(一)
- 使用自定义图标的MFC工程因原图标文件丢失无法building的解决办法
- h_errno
- Android--Demo_PullToRefresh(特效篇)
- xampp1.7 版本 安装步骤 以及mysql配置
- Python3 正则表达式
- 读取java项目下的文件
- 随笔-学习工具、教程 推荐
- Fragment生命周期
- 信息论、最大熵模型
- spring配置错误Could not find acceptable representation
- HTML5 - 用<figure/>添加插图和图题
- 【Java】内部类与外部类的互访使用小结
- TGroupon分销系统 delete_cart_goods.php 漏洞修复
- 关于IE中image的onload事件失效解决问题
- Saltstack SLS文件解读
- 如何在项目启动的时候做一些业务处理 (实现ServletContextListener)
- oracle游标透彻详解分析
- iOS 9 Spotlight搜索 OC版
- php-代码优化准则