亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Bootstrap圖片輪播組件Carousel使用方法詳解

 更新時(shí)間:2016年10月20日 17:11:59   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了Bootstrap圖片輪播組件Carousel使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Bootstrap是Twitter推出的一個(gè)開源的用于前端開發(fā)的工具包。它由Twitter的設(shè)計(jì)師Mark Otto和Jacob Thornton合作開發(fā),是一個(gè)CSS/HTML框架。Bootstrap提供了優(yōu)雅的HTML和CSS規(guī)范,它即是由動(dòng)態(tài)CSS語言Less寫成。Bootstrap一經(jīng)推出后頗受歡迎,一直是GitHub上的熱門開源項(xiàng)目,包括NASA的MSNBC(微軟全國廣播公司)的Breaking News都使用了該項(xiàng)目。

圖片輪播組件是一個(gè)在網(wǎng)頁中很常見的技術(shù),但是如果直接編寫的話,需要很長(zhǎng)的JavaScript編碼,同時(shí)也不好控制大小。

如果使用Bootstrap來編寫圖片輪播組件Carousel,則能夠節(jié)約很多時(shí)間。

同時(shí)說一下,Carousel這個(gè)詞的本義是回旋木馬。

一、基本目標(biāo)

在網(wǎng)頁編寫多張圖片的輪播組件Carousel,鼠標(biāo)放在上面自帶懸停效果,并且在每張圖片下面配有圖片說明。

由于筆者的電腦視頻錄制軟件比較渣,也覺得沒必要畫太多時(shí)間在這上面,覺得只要能說明問題就行,所以下面的GIF失色比較嚴(yán)重,但是基本的效果還算是展示出來了。

這個(gè)Bootstrap的圖片輪播組件Carousel,不兼容IE6與7,需要IE6支持的話,要去網(wǎng)站中下載Bootstrap的IE6組件支持(點(diǎn)擊打開鏈接)。同時(shí),在Google Chrome中圖片文件說明會(huì)滲有一點(diǎn)小黑色,不過不影響瀏覽:

在不同瀏覽器中的展示情況是不同的。IE8的話是這樣的效果:

二、基本思想

見下圖網(wǎng)頁布局:

三、制作過程

1、同之前《【JavaScript】使用Bootstrap來編寫一個(gè)在當(dāng)前網(wǎng)頁彈出的對(duì)話框,可以關(guān)閉,不用跳轉(zhuǎn),非彈窗》的第一步

因?yàn)樾枰褂肂ootstrap,所以先在官網(wǎng)下載組件即可,用于生產(chǎn)環(huán)境的Bootstrap版本,Bootstrap3對(duì)2并不兼容,建議直接根據(jù)其開發(fā)文檔使用Bootstrap3。本文也是根據(jù)Bootstrap3制作。同時(shí),Bootstrap3所提供的JavaScript效果需要到j(luò)Query1.11支持,可以到j(luò)Query官網(wǎng)中下載兼容舊瀏覽器IE6的jQuery1.11(點(diǎn)擊打開鏈接),而不是不兼容舊瀏覽器IE6的jQuery2。下載完之后,配置好站點(diǎn)目錄。把Bootstrap3直接解壓到站點(diǎn)目錄,而把jquery-1.11.1.js放到j(luò)s目錄,也就是與bootstrap.js同一目錄,站點(diǎn)文件夾的結(jié)構(gòu)大致如下:

2、以下是網(wǎng)頁的全代碼,下面一部分一部分進(jìn)行說明:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
 <link href="css/bootstrap.css" rel="stylesheet" media="screen">
 <script type="text/javascript" src="js/jquery-1.11.1.js"></script>
 <script type="text/javascript" src="js/bootstrap.js"></script>
 <title>圖片輪播Carousel</title>
 </head>

 <body>

 <div class="container">
 
 <div class="page-header">
 <h1>
 圖片輪播Carousel
 </h1>
 </div>

 <div style="width: 640px; height: 480px; margin-right: auto; margin-left: auto;">

 <div id="carousel" class="carousel slide" data-ride="carousel" data-interval="1000">

 <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>

 <div class="carousel-inner" role="listbox">
  
 <div class="item active">
 <a href="images/img0.jpg"><img src="images/img0.jpg" alt="img0"></a>
 <div class="carousel-caption">
 <h3>
 img0
 </h3>
 <p>
 我是img0的圖片說明
 </p>
 </div>
 </div>
  
 <div class="item">
 <a href="images/img10.jpg"><img src="images/img10.jpg" alt="img10"></a>
 <div class="carousel-caption">
 <h3>
 img10
 </h3>
  <p>
 我是img10的圖片說明
  </p>
 </div>
 </div>

 <div class="item">
 <a href="images/img2.jpg"><img src="images/img2.jpg" alt="img2"></a>
 <div class="carousel-caption">
 <h3>
 img2
 </h3>
 <p>
 我是img2的圖片說明
 </p>
 </div>
 </div>

 </div>

 <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> 
  <span class="glyphicon glyphicon-chevron-left"></span> </a>
 <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> 
  <span class="glyphicon glyphicon-chevron-right"></span> </a>

 </div>
 </div>
 </div>
 </body>
</html>

(1)<head>部分

<head>
 <!--聲明網(wǎng)頁編碼,自動(dòng)適應(yīng)瀏覽器的尺寸,要使用bootstrap的css,需要jquery支持,要使用bootstrap的js,標(biāo)題-->
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
 <link href="css/bootstrap.css" rel="stylesheet" media="screen">
 <script type="text/javascript" src="js/jquery-1.11.1.js"></script>
 <script type="text/javascript" src="js/bootstrap.js"></script>
 <title>圖片輪播Carousel</title>
 </head>

(2)<body>部分

先聲明一個(gè)容器container,這個(gè)容器能使網(wǎng)頁的所有元素自動(dòng)歸于網(wǎng)頁中央,之后在這個(gè)容器中編寫元素。

首先編寫頁頭,聲明一個(gè)頁頭,之后其里面寫入一段文本。

 <div class="page-header">
 <h1>
 圖片輪播Carousel
 </h1>
 </div>

之后定義一個(gè)未命名的圖層div,主要是用來規(guī)范圖片輪播組件用的。bootstrap的圖片輪播組件大小不能對(duì)其里面的元素,加入width與height參數(shù)進(jìn)行規(guī)定。這樣圖片輪播組件會(huì)失真。同時(shí)這個(gè)組件要居中,必須在div的style屬性中使用margin-right: auto; margin-left: auto;來約束,額外加入align="center"是根本一點(diǎn)效果都沒有。

最后是圖片組件各部分的詳細(xì)說明:

 <div style="width: 640px; height: 480px; margin-right: auto; margin-left: auto;">
 <!--圖片輪播組件的名稱為carousel,data-ride元素是bootstrap要求存在的,data-interval的值是每隔1000毫秒,也就是1秒換一張圖片,此值太小組件會(huì)失真-->
 <div id="carousel" class="carousel slide" data-ride="carousel" data-interval="1000">
 <!--這里定義有幾張圖片,如果再多一張圖片就再下面多加一項(xiàng),data-slide-to的值加一,首張圖片也就是第0張圖片必須要有class="active"否則組件無法工作-->
 <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>

 <div class="carousel-inner" role="listbox">
  <!--以下是各張的圖片的詳細(xì)編輯,首張圖片的class值必須為item active,余下的皆為item-->
 <div class="item active">
  <!--意為點(diǎn)擊img0.jpg這張圖片就打開img0.jpg的超級(jí)鏈接,如果不需要超級(jí)鏈接,則去掉<a>標(biāo)簽-->
 <a href="images/img0.jpg"><img src="images/img0.jpg" alt="img0"></a>
  <div class="carousel-caption">
  <!--圖片下的文字說明-->
 <h3>
 img0
 </h3>
 <p>
 我是img0的圖片說明
 </p>
 </div>
 </div>
  
 <div class="item">
 <a href="images/img10.jpg"><img src="images/img10.jpg" alt="img10"></a>
 <div class="carousel-caption">
 <h3>
 img10
 </h3>
  <p>
 我是img10的圖片說明
  </p>
 </div>
 </div>

 <div class="item">
 <a href="images/img2.jpg"><img src="images/img2.jpg" alt="img2"></a>
 <div class="carousel-caption">
 <h3>
 img2
 </h3>
 <p>
 我是img2的圖片說明
 </p>
 </div>
 </div>

 </div>
 
  <!--這里是組件中向左想右的兩個(gè)按鈕,固定存在的框架代碼-->
 <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> 
  <span class="glyphicon glyphicon-chevron-left"></span> </a>
 <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> 
  <span class="glyphicon glyphicon-chevron-right"></span> </a>

 </div>
 </div>

精彩專題分享:jQuery圖片輪播 JavaScript圖片輪播 Bootstrap圖片輪播

如果大家還想深入學(xué)習(xí),可以點(diǎn)擊這里進(jìn)行學(xué)習(xí),再為大家附3個(gè)精彩的專題:

Bootstrap學(xué)習(xí)教程

Bootstrap實(shí)戰(zhàn)教程

Bootstrap Table使用教程

Bootstrap插件使用教程

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript打印網(wǎng)頁指定區(qū)域的例子

    JavaScript打印網(wǎng)頁指定區(qū)域的例子

    這篇文章主要介紹了JavaScript打印網(wǎng)頁指定區(qū)域的例子,需要的朋友可以參考下
    2014-05-05
  • 網(wǎng)上抓的一個(gè)特效

    網(wǎng)上抓的一個(gè)特效

    網(wǎng)上抓的一個(gè)特效...
    2007-05-05
  • js 鼠標(biāo)點(diǎn)擊事件及其它捕獲

    js 鼠標(biāo)點(diǎn)擊事件及其它捕獲

    這段代碼是用來做,點(diǎn)擊一個(gè)按紐打開個(gè)div,在頁面空白處點(diǎn)擊鼠標(biāo)隱藏這個(gè)div
    2009-06-06
  • javascript實(shí)現(xiàn)拖拽碰撞檢測(cè)

    javascript實(shí)現(xiàn)拖拽碰撞檢測(cè)

    這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)拖拽碰撞檢測(cè),碰撞改變顏色,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • JavaScript中實(shí)現(xiàn)Map的示例代碼

    JavaScript中實(shí)現(xiàn)Map的示例代碼

    本篇文章給大家介紹javascript中實(shí)現(xiàn)map的示例代碼,代碼寫的簡(jiǎn)單易懂,可以獲取、刪除鍵值,剛興趣的朋友跟著腳本之家小編一起學(xué)習(xí)吧。
    2015-09-09
  • JS 控件事件小結(jié)

    JS 控件事件小結(jié)

    事件對(duì)于控件來說至關(guān)重要,控件的消息通信機(jī)制使用事件的成本最低,但是對(duì)于JS控件來說有一些麻煩需要解決,JS類本身不支持事件,DOM模型支持的事件僅適應(yīng)于瀏覽器的DOM節(jié)點(diǎn)。所以創(chuàng)建一套事件是我們寫控件之前要做的
    2012-10-10
  • JS動(dòng)態(tài)顯示倒計(jì)時(shí)效果

    JS動(dòng)態(tài)顯示倒計(jì)時(shí)效果

    這篇文章主要介紹了JS實(shí)現(xiàn)倒計(jì)時(shí)效果動(dòng)態(tài)顯示倒計(jì)時(shí)功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • Three.js加載外部模型的教程詳解

    Three.js加載外部模型的教程詳解

    這篇文章主要介紹了Three.js外部模型加載的教程詳解,在文章給大家補(bǔ)充介紹了three.js 外部模型加載json的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-11-11
  • 微信小程序報(bào)錯(cuò):does?not?have?a?method?"xxxx"?to?handle?event?"tap"的解決方案

    微信小程序報(bào)錯(cuò):does?not?have?a?method?"xxxx"?to?ha

    這篇文章主要給大家介紹了關(guān)于微信小程序報(bào)錯(cuò):does?not?have?a?method?"xxxx"?to?handle?event?"tap"的解決方案,文中將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下
    2023-01-01
  • 二行代碼解決全部網(wǎng)頁木馬

    二行代碼解決全部網(wǎng)頁木馬

    還是掛馬問題,這段時(shí)間,我漸漸感到壓力,頭大,通過QQ或MSN加我的人越來越多,我最近自己的工作本來就忙得不亦樂乎。哎,想想,還是要抽空來來幫幫大家。
    2008-03-03

最新評(píng)論