欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Bootstrap圖片輪播組件使用實例解析

 更新時間:2016年06月30日 17:00:54   作者:yongh701  
圖片輪播組件是一個在網(wǎng)頁中很常見的技術(shù),這篇文章主要為大家詳細介紹了Bootstrap圖片輪播組件使用實例,感興趣的小伙伴們可以參考一下

使用Bootstrap來編寫圖片輪播組件Carousel,則能夠節(jié)約很多時間,圖片輪播組件是一個在網(wǎng)頁中很常見的技術(shù),但是如果直接編寫的話,需要很長的JavaScript編碼,同時也不好控制大小。 
同時說一下,Carousel這個詞的本義是回旋木馬。 

一、基本目標
在網(wǎng)頁編寫多張圖片的輪播組件Carousel,鼠標放在上面自帶懸停效果,并且在每張圖片下面配有圖片說明。 
由于筆者的電腦視頻錄制軟件比較渣,也覺得沒必要畫太多時間在這上面,覺得只要能說明問題就行,所以下面的GIF失色比較嚴重,但是基本的效果還算是展示出來了。 
這個Bootstrap的圖片輪播組件Carousel,不兼容IE6與7,需要IE6支持的話,要去這個網(wǎng)站中下載Bootstrap的IE6組件支持(點擊打開鏈接)。同時,在Google Chrome中圖片文件說明會滲有一點小黑色,不過不影響瀏覽: 

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

二、基本思想
見下圖網(wǎng)頁布局: 

三、制作過程
1、同之前《Bootstrap編寫一個在當前網(wǎng)頁彈出可關(guān)閉的對話框 非彈窗》的第一步(點擊打開鏈接) 
因為需要使用Bootstrap,所以先在官網(wǎng)(點擊打開鏈接)下載組件即可,用于生產(chǎn)環(huán)境的Bootstrap版本,Bootstrap3對2并不兼容,建議直接根據(jù)其開發(fā)文檔使用Bootstrap3。本文也是根據(jù)Bootstrap3制作。同時,Bootstrap3所提供的JavaScript效果需要到j(luò)Query1.11(點擊打開鏈接)支持,可以到j(luò)Query官網(wǎng)中下載兼容舊瀏覽器IE6的jQuery1.11,而不是不兼容舊瀏覽器IE6的jQuery2。下載完之后,配置好站點目錄。把Bootstrap3直接解壓到站點目錄,而把jquery-1.11.1.js放到j(luò)s目錄,也就是與bootstrap.js同一目錄,站點文件夾的結(jié)構(gòu)大致如下: 

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

 <!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)頁編碼,自動適應(yīng)瀏覽器的尺寸,要使用bootstrap的css,需要jquery支持,要使用bootstrap的js,標題-->
 <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>部分

先聲明一個容器container,這個容器能使網(wǎng)頁的所有元素自動歸于網(wǎng)頁中央,之后在這個容器中編寫元素。
 首先編寫頁頭,聲明一個頁頭,之后其里面寫入一段文本。

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

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

 <div style="width: 640px; height: 480px; margin-right: auto; margin-left: auto;">
 <!--圖片輪播組件的名稱為carousel,data-ride元素是bootstrap要求存在的,data-interval的值是每隔1000毫秒,也就是1秒換一張圖片,此值太小組件會失真-->
 <div id="carousel" class="carousel slide" data-ride="carousel" data-interval="1000">
 <!--這里定義有幾張圖片,如果再多一張圖片就再下面多加一項,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">
   <!--以下是各張的圖片的詳細編輯,首張圖片的class值必須為item active,余下的皆為item-->
 <div class="item active">
    <!--意為點擊img0.jpg這張圖片就打開img0.jpg的超級鏈接,如果不需要超級鏈接,則去掉<a>標簽-->
 <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>


如果大家還想深入學習,可以點擊這里進行學習,再為大家附3個精彩的專題:

Bootstrap學習教程

Bootstrap實戰(zhàn)教程

Bootstrap插件使用教程

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • canvas學習之API整理筆記(二)

    canvas學習之API整理筆記(二)

    本篇文章的主要內(nèi)容包括高級動畫、像素操作、性能優(yōu)化等知識點,講解每個知識點的同時還會有一些酷炫的demo。下面跟著小編一起來看下吧
    2016-12-12
  • 詳解Bootstrap網(wǎng)格垂直和水平對齊方式

    詳解Bootstrap網(wǎng)格垂直和水平對齊方式

    網(wǎng)格在網(wǎng)頁布局中是一個重點和難點,布局是網(wǎng)頁設(shè)計的起點和基礎(chǔ),本文主要介紹了Bootstrap網(wǎng)格垂直和水平對齊方式,感興趣的可以了解一下
    2021-07-07
  • JS自調(diào)用匿名函數(shù)具體實現(xiàn)

    JS自調(diào)用匿名函數(shù)具體實現(xiàn)

    定義一個函數(shù)用做臨時的命名空間,在這個命名空間內(nèi)定義的變量都不會污染到全局命名空間,需要的朋友可以參考下
    2014-02-02
  • 前端深入理解Typescript泛型概念

    前端深入理解Typescript泛型概念

    這篇文章主要介紹了前端深入理解Typescript泛型概念,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-03-03
  • JavaScript使用百度ECharts插件繪制餅圖操作示例

    JavaScript使用百度ECharts插件繪制餅圖操作示例

    這篇文章主要介紹了JavaScript使用百度ECharts插件繪制餅圖操作,結(jié)合實例形式分析了JavaScript使用百度ECharts插件繪制餅圖的原理、步驟及相關(guān)操作注意事項,需要的朋友可以參考下
    2019-11-11
  • javascript中類型判斷的最佳方式

    javascript中類型判斷的最佳方式

    這篇文章介紹了javascript中類型判斷的最佳方式,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • JavaScript引用類型Function實例詳解

    JavaScript引用類型Function實例詳解

    這篇文章主要介紹了JavaScript引用類型Function,結(jié)合實例形式詳細分析了javascript引用類型Function概念、定義、原理、相關(guān)使用技巧與操作注意事項,需要的朋友可以參考下
    2018-08-08
  • JavaScript實現(xiàn)word轉(zhuǎn)png的示例代碼

    JavaScript實現(xiàn)word轉(zhuǎn)png的示例代碼

    這篇文章主要為大家詳細介紹了如何使用JavaScript實現(xiàn)word轉(zhuǎn)png的功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-02-02
  • JavaScript 事件代理需要注意的地方

    JavaScript 事件代理需要注意的地方

    這篇文章主要介紹了JavaScript 事件代理需要注意的地方,幫助大家更好的理解和學習JavaScript,感興趣的朋友可以了解下
    2020-09-09
  • JavaScript實現(xiàn)小程序圖片裁剪功能的示例代碼

    JavaScript實現(xiàn)小程序圖片裁剪功能的示例代碼

    這篇文章主要為大家詳細介紹了如何利用JavaScript實現(xiàn)小程序圖片裁剪功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起了解一下
    2023-03-03

最新評論