简易呼吸轮播图
一个叫做简易呼吸的轮播图~~~~

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
| <html> <head> <meta charset="UTF-8"> <title>简易呼吸轮播图</title> <style type="text/css"> *{ margin: 0px; padding: 0px; } .fade-box{ width: 900px; height: 540px; border: 1px solid #000; margin: 100px auto; position: relative; } .fade-box ul{ list-style: none; } .fade-box ul li{ width: 900px; height: 540px; position: absolute; top:0px; left:0px; display: none; } .fade-box ul li img{ width: 100%; height:100%; } .fade-box ul li.current{ display: block; } .fade-box .circle{ position: absolute; bottom:20px; width:200px; height: 30px; left:50%; margin-left:-100px; } .fade-box .circle ol{ list-style: none; } .fade-box .circle ol li{ float: left; width: 20px; height: 20px; border-radius: 20px; margin-right: 30px; background: #ccc; } .fade-box .circle ol .current{ background:skyblue } .fade-box .fade-btn a{ display: block; width: 40px; height: 80px; position: absolute; font-size: 30px; color: #fff; background: rgba(0,0,0,0.7); line-height: 80px; text-decoration: none; top:50%; margin-top: -40px; text-align: center; } .fade-box .fade-btn a:nth-child(1){ left:0px; } .fade-box .fade-btn a:nth-child(2){ right:0px; } </style> </head> <body> <div class="fade-box"> <ul> <li><a href="javascript:void(0);"><img src="http://opfmdske3.bkt.clouddn.com/avatar.jpg" alt=""></a></li> <li><a href="javascript:void(0);"><img src="http://opfmdske3.bkt.clouddn.com/3c56f44e251f95ca3f1ef39dc1177f3e6609528b.jpg" alt=""></a></li> <li><a href="javascript:void(0);"><img src="http://opfmdske3.bkt.clouddn.com/110G31K5-6.jpg" alt=""></a></li> <li><a href="javascript:void(0);"><img src="http://opfmdske3.bkt.clouddn.com/110G31K5-6.jpg" alt=""></a></li> </ul> <div class="btn"> <a href="javascript:void(0);"><</a> <a href="javascript:void(0);">></a> </div> <div class="circle"> <ol> <li></li> <li></li> <li></li> <li></li> </ol> </div> </div> </body> <script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.js"></script> <script> $(function() { var bannerImgs = $('.fade-box ul li'); var circles = $('.fade-box .circle ol li'); var leftBtn = $('.fade-box .btn a:eq(0)'); var rightBtn = $('.fade-box .btn a:eq(1)'); var index = 0; circles.eq(0).addClass('current'); bannerImgs.eq(0).fadeIn(); //判断方向 function runDir(dir){ if (dir == 1) { if (bannerImgs.is(':animated')) { return; } bannerImgs.eq(index).fadeOut(); index++; if (index>bannerImgs.length-1){ index = 0; } bannerImgs.eq(index).fadeIn(); circles.eq(index).addClass('current').siblings().removeClass('current'); }else if (dir == 0) { if (bannerImgs.is(':animated')) { return; } bannerImgs.eq(index).fadeOut(); index--; if (index<0){ index = bannerImgs.length-1; } bannerImgs.eq(index).fadeIn(); circles.eq(index).addClass('current').siblings().removeClass('current'); }else{ throw '请填写正确参数'; } } rightBtn.click(function () { runDir(1); }); leftBtn.click(function () { runDir(0); }); circles.mouseenter(function () { if (bannerImgs.is(":animated")) { return; } bannerImgs.eq(index).fadeOut(); index = $(this).index(); bannerImgs.eq(index).fadeIn(); circles.eq(index).addClass('current').siblings().removeClass('current'); }) $('.fade-box').mouseenter(function () { clearInterval(timer); }); $('.fade-box').mouseleave(function () { timer = setInterval(function () { return runDir(1); },1000) }) var timer = setInterval(function () { return runDir(1); },2000); }) </script> </html>
|