English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
HTML code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Carousel Practice</title> <link rel="stylesheet" href="css/css.css" rel="external nofollow" type="text/css"/> </head> <body> <ul class="back"> <!-- Background image --> <li class="l1></li> <li class="l2></li> <li class="l3></li> <li class="l4></li> <li class="l5></li> </ul> <ul class="point"> <!-- Control button --> <li class="active"></li> <li></li> <li></li> <li></li> <li></li> </ul> <div class="btn"> <!-- left and right control buttons --> <span class="prev"></span> <span class="next"></span> </div> </body> <script src="js/jquery-1.7.2.js"></script> <script src="js/jq.js"></script> </html>
css code:
*{margin:0; padding: 0;} ul li{list-style: none;} .back{height: 400px; overflow: hidden; margin-top:100px;} .back li{width: 100%; height: 400px; margin:0 auto;} .back li.l1{background: red;} .back li.l2{background: yellow;} .back li.l3{background: blue;} .back li.l4{background: black;} .back li.l5{background: green;} .point{text-align: center; margin-top: -30px;} .point li{ width: 20px; height: 20px; border:2px solid #fff; border-radius: 10px; box-sizing:border-box; display: inline-block;} .point li.active{background: #fff;} .btn{ position: relative;} .btn span{ display: inline-block; vertical-align: top; width: 100px; height: 100px; background: rgba(0,0,0,.5); position: absolute; top:-235px; cursor: pointer;} .btn .prev {left: 0} .btn .next { right: 0;}
js code:
$(function() { function banner(a, b, c, d, e) { // a is the background image, b is active, c is the corresponding button of the background, d is the previous page, e is the next page index=0; len=$(a).length-1; function teb(index){ $(c).eq(index).addClass(b).siblings('').removeClass(b); $(a).eq(index).fadeIn(300).addClass('curr').siblings('').fadeOut(300).removeClass('curr'); }; $(c).click(function(){ index=$(this).index(); teb(index); }); $(d).click(function(){ index--; if(index<0){ index=len; }; teb(index); }); $(e).click(function(){ index++; if(index>len){ index=0; }; teb(index); }); function timeRun(){ time=setInterval(function(){ index++; if(index>len){ index=0; }; teb(index); },3000); }; timeRun(); }; banner('.back>li','active','.point>li','.prev','.next'); });
That's all for this article. I hope the content of this article can bring you some help in learning or work, and I also hope to support the呐喊 tutorial more!
Declaration: The content of this article is from the Internet, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (When reporting via email, please replace # with @) to report violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.