使用背景圖片進行交換



說明

要設定背景圖片,可以在 <div> 標記中使用 data-interchange 屬性。你可以傳遞圖片路徑來設定相匹配規則的 background-image 屬性。

示例

以下示例演示了在 Foundation 中使用帶有背景圖片的 interchange −

<!DOCTYPE html>
<html>
   <head>
      <title>Foundation Template</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/css/foundation.css">
      
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/foundation.min.js"></script>
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js"></script>
   </head>

   <body>
      <div data-interchange = "[/foundation/images/foundation-plugin/smallback.jpg, (small)], 
         [/foundation/images/foundation-plugin/mediumback.jpg, (medium)], 
         [/foundation/images/foundation-plugin/background.jpg, (large)]">
      
         <h2>Welcome to TutorialsPoint</h2>
         <p>Lorem Ipsum is simply dummy text of the printing and typesetting 
            industry. Lorem Ipsum has been the industry's standard dummy text ever since 
            the 1500s, when an unknown printer took a galley of type and scrambled it to 
            make a type specimen book.
         </p>
      </div>
      
      <script>
         $(document).ready(function() {
            $(document).foundation();
         })
      </script>
   </body>
</html>

輸出

讓我們執行以下步驟,看看上面給出的程式碼是如何工作的 −

  • 將上面給出的 html 程式碼儲存到 background_image.html 檔案中。

  • 在瀏覽器中開啟此 HTML 檔案,顯示的輸出如下。

foundation_plugins.htm
廣告
© . All rights reserved.