利用BootStrap的Carousel.js實(shí)現(xiàn)輪播圖動(dòng)畫(huà)效果
前期準(zhǔn)備:
1.jquery.js。
2.bootstrap的carousel.js。
3.bootstrap.css。
一起來(lái)看代碼吧:
頁(yè)面比較丑,希望大家不要介意哦嘻嘻
效果圖:
html+js:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>my love-首頁(yè)</title> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/index.css"> <link href="favicon.ico" rel="shortcut icon" /> <script src="js/jquery.js" type="text/javascript"></script> <script src="js/carousel.js" type="text/javascript"></script> </head> <body> <div class="index-content"> <div class="index-header"> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="javascript:void(0)">首頁(yè)</a> </div> <div> <ul class="nav navbar-nav"> <li class="active"><a href="#section1" class="con">向日葵花</a></li> <li><a href="#section2" class="con">萌萌噠的狗狗</a></li> <li><a href="#section3" class="con">好吃噠</a></li> </ul> </div> </div> </nav> </div> <div class="index-body"> <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner" role="listbox"> <div class="item active"> <img src="image/indexOne.jpg" alt="向日葵" class="images"> </div> <div class="item"> <img src="image/indexTwo.jpg" alt="萌萌噠狗狗" class="images"> </div> <div class="item"> <img src="image/indexThree.jpg" alt="好吃噠" class="images"> </div> </div> <!-- Controls --> <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> <div class="index-footer"> <div class="footer-centent"> Copyright ©2016 愛(ài)喝酸奶的吃貨 </div> </div> </div> <script type="text/javascript"> $(function() { $(".navbar-nav li").each(function(index) { $(this).click(function() { $("li.active").removeClass("active"); //注意這里 $(this).addClass("active"); //注意這里 $(".carousel-inner div.active").removeClass("active"); $(".carousel-inner div").eq(index).addClass("active"); }); }); window.setInterval(function() { $(".carousel-inner div").each(function(index) { if ($(this).hasClass("active")) { $(".navbar-nav li.active").removeClass("active"); $(".navbar-nav li").eq(index).addClass("active"); } }); }, 100); }); </script> </body> </html>
index.css
.container-fluid { padding-left: 200px; } .navbar-default { background-color: #308dca; } .navbar-brand { font-size: 34px; height: 70px; } .navbar-nav>li>a { font-size: 19px; } .navbar-default .navbar-brand, .navbar-default .navbar-nav>li>a, .navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>li>a:focus { color: #fff; } .navbar-brand, .navbar-nav>li>a { line-height: 40px; } .navbar-default .navbar-nav>.active>a, .navbar-default .navbar-nav>.active>a:hover, .navbar-default .navbar-nav>.active>a:focus { color: #fff; background-color: #2276bf; } .index-body { margin: 0 auto; } .carousel-inner { height: 490px; } .index-body, .images { width: 900px; } .index-footer { margin-top: 20px; color: #fff; background-color: #2276bf; } .footer-centent { width: 300px; font-size: 20px; line-height: 55px; margin: 0 auto; height: 60px; }
大家在自己設(shè)計(jì)demo的時(shí)候注意下,class為index-body的div和img的寬度要設(shè)置一樣,否則會(huì)出現(xiàn)以下情況:
以上所述是小編給大家介紹的利用BootStrap的Carousel.js實(shí)現(xiàn)輪播圖動(dòng)畫(huà)效果,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- BootStrap實(shí)現(xiàn)手機(jī)端輪播圖左右滑動(dòng)事件
- Bootstrap幻燈片輪播圖支持觸屏左右手勢(shì)滑動(dòng)的實(shí)現(xiàn)方法
- Bootstrap每天必學(xué)之響應(yīng)式導(dǎo)航、輪播圖
- Bootstrap開(kāi)發(fā)實(shí)戰(zhàn)之響應(yīng)式輪播圖
- 使用BootStrap建立響應(yīng)式網(wǎng)頁(yè)——通欄輪播圖(carousel)
- BootStrap實(shí)現(xiàn)輪播圖效果(收藏)
- 在bootstrap中實(shí)現(xiàn)輪播圖實(shí)例代碼
- Bootstrap實(shí)現(xiàn)基于carousel.js框架的輪播圖效果
- bootstrap輪播圖示例代碼分享
- bootstrap實(shí)現(xiàn)輪播圖效果
相關(guān)文章
經(jīng)典的間隔時(shí)間滾動(dòng)新聞(圖片),可控制滾動(dòng)
經(jīng)典的間隔時(shí)間滾動(dòng)新聞(圖片),可控制滾動(dòng) 其實(shí)這個(gè)也挺多網(wǎng)站用到的,簡(jiǎn)單又實(shí)用。(2010-05-05javascript html5移動(dòng)端輕松實(shí)現(xiàn)文件上傳
這篇文章主要為大家詳細(xì)介紹了javascript html5移動(dòng)端輕松實(shí)現(xiàn)文件上傳的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03js 將多個(gè)對(duì)象合并成一個(gè)對(duì)象 assign方法的實(shí)現(xiàn)
這篇文章主要介紹了js 將多個(gè)對(duì)象合并成一個(gè)對(duì)象 assign方法的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09不依賴Flash和任何JS庫(kù)實(shí)現(xiàn)文本復(fù)制與剪切附源碼下載
本篇文章給大家分享的文本復(fù)制與剪切板功能,實(shí)現(xiàn)此功能不依賴falsh插件和任何js庫(kù)實(shí)現(xiàn)的,感興趣的朋友一起看看吧2015-10-10JS/jQ實(shí)現(xiàn)免費(fèi)獲取手機(jī)驗(yàn)證碼倒計(jì)時(shí)效果
這篇文章主要介紹了JS/jQ實(shí)現(xiàn)免費(fèi)獲取手機(jī)驗(yàn)證碼倒計(jì)時(shí)效果的相關(guān)資料,通過(guò)定義兩個(gè)接口,發(fā)送驗(yàn)證請(qǐng)求和返回?cái)?shù)據(jù)驗(yàn)證手機(jī)號(hào)和驗(yàn)證是否一致,后臺(tái)根據(jù)接口去實(shí)現(xiàn),需要的朋友可以參考下2016-06-06英文首字母全大寫(xiě)的js實(shí)現(xiàn)腳本
輸入內(nèi)容活直接點(diǎn)轉(zhuǎn)換即可,講單詞的首字母大寫(xiě)。2008-09-09IntersectionObserver實(shí)現(xiàn)圖片懶加載的示例
下面小編就為大家?guī)?lái)一篇IntersectionObserver實(shí)現(xiàn)圖片懶加載的示例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09