基础 - 使用图片交换



描述

使用图片交换功能,您可以按照屏幕大小设置图像大小,如大、中、小。图像将在小屏幕设备上显示得更小。要确定为哪个图片服务的用户设备,使用 CSS 媒体查询。

示例

以下示例展示了在 Foundation 中使用图片交换 −

<!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>
      <h2>Example of use with images</h2>
      <img data-interchange = "[/foundation/images/foundation-plugin/small.jpg, (default)], 
         [/foundation/images/foundation-plugin/small.jpg, (small)], 
         [/foundation/images/foundation-plugin/medium.jpg, (medium)]">
      
      <script>
         $(document).ready(function() {
            $(document).foundation();
         })
      </script>
   </body>
</html>

输出

让我们执行以下步骤,了解上面给定的代码如何工作 −

  • 保存上面给定的 HTML 代码use_images.html文件。

  • 在浏览器中打开此 HTML 文件,显示如下所示的输出。

foundation_plugins.htm
广告
© . All rights reserved.