自定义图标,颜色和图像(Custom Icons, Colors and Images)

优质
小牛编辑
134浏览
2023-12-01

描述 (Description)

您可以分别使用data-option-icondata-option-colordata-option-image属性在智能选择上定义自定义图标,颜色或图像。

例子 (Example)

以下示例演示了在Framework7中自定义图标,颜色和图像中使用智能选择 -

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, 
         maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
      <meta name = "apple-mobile-web-app-capable" content = "yes" />
      <meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
      <title>Custom icons, colors and images</title>
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
   </head>
   <body>
      <div class = "views">
         <div class = "view view-main">
            <div class = "navbar">
               <div class = "navbar-inner">
                  <div class = "left"> </div>
                  <div class = "center sliding">Smart Select Custom Icons, Colors and Images</div>
                  <div class = "right"> </div>
               </div>
            </div>
            <div class = "pages navbar-through">
               <div data-page = "home" class = "page">
                  <div class = "page-content">
                     <div class = "list-block">
                        <ul>
                           <li>
                              <a href = "#" class = "item-link smart-select">
                                 <select name = "countries">
                                    <option value = "India" selected data-option-image = "images/ind.gif">India</option>
                                    <option value = "Newz = Zealnad" data-option-image = "images/arg.gif">Argentina</option>
                                    <option value = "Srilanka" data-option-color = "red" data-option-image = "images/bgm.gif">Belgium</option>
                                 </select>
                                 <div class = "item-content">
                                    <div class = "item-inner">
                                       <div class = "item-title">Countries</div>
                                    </div>
                                 </div>
                              </a>
                           </li>
                        </ul>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>
      <script>
         // here initialize the app
         var myApp = new Framework7 ({
            animateNavBackIcon:true
         });
         // If your using custom DOM library, then save it to $$ variable
         var $$ = Dom7;
         // Add the view
         var mainView = myApp.addView('.view-main', {
            // enable the dynamic navbar for this view
            dynamicNavbar: true
         });
      </script>
   </body>
</html>

输出 (Output)

让我们执行以下步骤,看看上面给出的代码是如何工作的 -

  • 将上面给出的HTML代码保存为服务器根文件夹中的smart_select_icons_colors_images.html文件。

  • 以http://localhost/smart_select_icons_colors_images.html打开此HTML文件,输出显示如下。

  • 输出显示使用data-option-icon,data-option-color和data-option-image来定义智能选择的自定义图标,颜色或图像。

  • 当您单击名为“国家/地区”的选项时,将显示包含图标,颜色或图像的不同国家/地区列表,您可以选择任一选项。