Bootstrap 滾動監聽+小工具+Flex(彈性)佈局+多媒體對象

来源:https://www.cnblogs.com/chenyingying0/archive/2020/04/20/12736533.html
-Advertisement-
Play Games

Bootstrap 滾動監聽 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>demo1</title> <meta name="viewport" content="width=device-width, ...


Bootstrap 滾動監聽

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo1</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <style>
        body{
            margin:10px;
            padding:10px;
        }
        .navbar-item{flex:1;}
    </style>
</head>
<body data-spy="scroll" data-target=".navbar" data-offset="50" style="position: relative;">
    <nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
        <ul class="navbar-nav" style="width:100%;">
            <li class="nav-item">
                <a href="#item1" class="nav-link">item1</a>
            </li>
            <li class="nav-item">
                <a href="#item2" class="nav-link">item2</a>
            </li>
            <li class="nav-item">
                <a href="#item3" class="nav-link">item3</a>
            </li>
            <li class="nav-item">
                <a href="#item4" class="nav-link">item4</a>
            </li>
        </ul>
    </nav>

    <div id="item1" class="container-fluid bg-success" style="padding:70px 0">
        <h1>Section 1</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="item2" class="container-fluid bg-warning" style="padding:70px 0">
        <h1>Section 2</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="item3" class="container-fluid bg-danger" style="padding:70px 0">
        <h1>Section 3</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="item4" class="container-fluid bg-info" style="padding:70px 0">
        <h1>Section 4</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>


</body>
</html>

 

 

 

把滾動監聽加在body標簽上,是正常的

當我嘗試加在某個div上時,發現滾動監聽似乎無效了

各位有知道原因的麽

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo1</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <style>
        body{
            margin:10px;
            padding:10px;
        }
        .navbar-item{flex:1;}
    </style>
</head>
<body>

<div data-spy="scroll" data-target=".navbar" data-offset="50" style="width:300px;margin:0 auto;position: relative;">
    <nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top" style="width:300px;margin:0 auto;">
        <ul class="navbar-nav" style="width:100%;">
            <li class="nav-item">
                <a href="#item1" class="nav-link">item1</a>
            </li>
            <li class="nav-item">
                <a href="#item2" class="nav-link">item2</a>
            </li>
            <li class="nav-item">
                <a href="#item3" class="nav-link">item3</a>
            </li>
            <li class="nav-item">
                <a href="#item4" class="nav-link">item4</a>
            </li>
        </ul>
    </nav>

    <div id="item1" class="container-fluid bg-success" style="padding:70px 0">
        <h1>Section 1</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="item2" class="container-fluid bg-warning" style="padding:70px 0">
        <h1>Section 2</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="item3" class="container-fluid bg-danger" style="padding:70px 0">
        <h1>Section 3</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="item4" class="container-fluid bg-info" style="padding:70px 0">
        <h1>Section 4</h1>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>

</div>


</body>
</html>

 

 

 

垂直滾動監聽:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo1</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <style>
        .nav-pills{
            position:fixed;
            top:20px;
        }
        .col-8 div{
            height:800px;
        }
    </style>
</head>
<body data-spy="scroll" data-target="#navbar" data-offset="1" style="position: relative;">
    <div class="container-fluid">
        <div class="row">
            <nav class="col-4" id="navbar">
                <ul class="nav nav-pills flex-column">
                    <li class="nav-item">
                        <a href="#item1" class="nav-link">item1</a>
                    </li>
                    <li class="nav-item">
                        <a href="#item2" class="nav-link">item2</a>
                    </li>
                    <li class="nav-item">
                        <a href="#item3" class="nav-link">item3</a>
                    </li>
                    <li class="nav-item">
                        <a href="#item4" class="nav-link">item4</a>
                    </li>
                </ul>
            </nav>

            <div class="col-8">
                <div id="item1" class="container-fluid bg-success" style="padding:70px 0">
                    <h1>Section 1</h1>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                </div>
                <div id="item2" class="container-fluid bg-warning" style="padding:70px 0">
                    <h1>Section 2</h1>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                </div>
                <div id="item3" class="container-fluid bg-danger" style="padding:70px 0">
                    <h1>Section 3</h1>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                </div>
                <div id="item4" class="container-fluid bg-info" style="padding:70px 0">
                    <h1>Section 4</h1>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
                </div>
            </div>
        </div>
    </div>

</body>
</html>

 

 

 

 

Bootstrap4 小工具

使用 border 類可以添加或移除邊框:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo1</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <style>
        div{
            display: inline-block;
            width:100px;
            height:100px;
            margin:20px;
        }
    </style>
</head>
<body>
    <div class="border"></div>
    <div class="border-0"></div>
    <div class="border border-top-0"></div>
    <div class="border border-right-0"></div>
    <div class="border border-bottom-0"></div>
    <div class="border border-left-0"></div>

</body>
</html>

 

 

 

Bootstrap4 提供了一些類來設置邊框顏色:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo1</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <style>
        div{
            display: inline-block;
            width:100px;
            height:100px;
            margin:20px;
        }
    </style>
</head>
<body>
    <div class="border border-primary">primary</div>
    <div class="border border-secondary">secondary</div>
    <div class="border border-info">info</div>
    <div class="border border-warning">warning</div>
    <div class="border border-danger">danger</div>
    <div class="border border-success">success</div>
    <div class="border border-light">light</div>
    <div class="border border-dark">dark</div>
    <div class="border border-white">white</div>

</body>
</html>

 

 

 

使用rounded 類可以添加圓角邊框:

<!DOCTYPE html>
<html lang="en">
<head>
    <
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Async 和 Awaiit 是 Promise 的擴展,我們知道 JavaScript 是單線程的,使用 Promise 之後可以使非同步操作的書寫更簡潔,而 Async 使 Promise 像同步操作 一、Async Async 自動將常規函數轉換成 Promise,返回值一個 Promise 對 ...
  • 寫一個自定義的數組排序,可以自己制定數組的排序規則: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-s ...
  • 浮點數運算的誤差 在 JavaScript 中整數和浮點數都屬於number 數據類型,所有數字都是使用64位浮點數形式儲存,遵循IEEE-754雙精度標準存儲,即便整數也是如此。 所以我們在列印 1.00 這樣的浮點數的結果是 1 而非 1.00。而有時候用浮點數進行數學運算的時候,發現居然會有一 ...
  • Vue.js 計算屬性 計算屬性關鍵詞: computed。 計算屬性在處理一些複雜邏輯時是很有用的。 可以看下以下反轉字元串的例子: <template> <div id="app"> <p>{{info}}</p> <p>{{reverse}}</p> </div> </template> <s ...
  • 摘要 最近在開發H5,就在開發過程中發現H5存在著一些坑,所以就總結一下在開發過程中遇到的坑以及解決辦法,本文會持續的更新,同時也歡迎大家一起評論分享H5開發中遇到的坑、解決辦法等。 常見的通用的H5開發問題 IOS端-H5開發問題 · 輸入法隱藏頁面留白 問題現象:iOS端軟鍵盤失去焦點(隱藏)後 ...
  • Vue.js 模板語法 數據綁定最常見的形式就是使用 {{...}}(雙大括弧)的文本插值: 使用 v-html 指令用於輸出 html 代碼: HTML 屬性中的值應使用 v-bind 指令。 以下實例判斷 use 的值,如果為 true 使用 class1 類的樣式,否則不使用該類: <temp ...
  • 1.in關鍵字 屬性名 in 對象,用來判斷某個屬性在對象中是否存在與其嚴格相等的屬性名,返回boolean值 屬性名必須是字元串或數字 var obj = { a : 1, b : 2 } console.log('a' in obj);//返回true,obj對象中存在a屬性名 var arr ...
  • flex很早就出來了,但是由於相容性很差,一直不火。 目前個人只在手機端中小心翼翼的使用flex,整理個模板出來,橫軸的! 模板css: .children{ height: 20px; border: 1px solid red; margin: 2px; } .parent{ width: 10 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...