jQuery和Bootstrap 5 可自定义Bootstrap图标选择器

  • 源码大小:46.99KB
  • 所需积分:1积分
  • 源码编号:19JP-3593
  • 浏览次数:485次
  • 最后更新:2023年06月30日
  • 所属栏目:其他
本站默认解压密码:19jp.com 或 19jp_com

简介

用于创建自定义web界面的流行Bootstrap 5框架有很多不错的好处;然而,有一点需要注意,那就是可以从庞大的Bootstrap图标目录中轻松选择图标,但现在你可以通过这个新插件获得这个选项。

这是一个完全可定制的jQuery,它使用Bootstrap 5 popover组件来创建一个可过滤的图标选择器界面,它提供了一种从1600多个Bootstrap SVG图标中选择图标的简单方法。

请参阅实际操作:

如何使用它:

1.在文档中加载必要的jQuery库、Bootstrap 5框架和Bootstrap Icons。

  1. <!-- jQuery -->
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3.  
  4. <!-- Bootstrap 5 -->
  5. <link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
  6. <script src="/path/to/cdn/bootstrap.bundle.min.js"></script>
  7.  
  8. <!-- Bootstrap Icons -->
  9. <link rel="stylesheet" href="/path/to/cdn/bootstrap-icons.min.css" />

2.下载插件并加载以下JavaScript和CSS文件。

  1. <link href="/dist/css/bootstrapicons-iconpicker.css" rel="stylesheet" />
  2. <script src="/dist/js/bootstrapicon-iconpicker.js"></script>

3.将引导图标选取器连接到您指定的输入字段。

  1. <input type="text" class="form-control iconpicker" placeholder="Icon Picker" aria-label="Icone Picker" aria-describedby="basic-addon1" />
  1. $(function(){
  2. $('.iconpicker').iconpicker();
  3. });

4.在初始化图标选择器时,您可以提供更改其外观的选项。所有可能的选项:

  1. $('.iconpicker').iconpicker({
  2.  
  3. // Icon picker title
  4. title: false,
  5.  
  6. // Selected icon on init
  7. selected: false,
  8.  
  9. // Default icon
  10. defaultValue: false,
  11.  
  12. // inline
  13. // topLeftCorner
  14. // topLeft
  15. // top (center)
  16. // topRight
  17. // topRightCorner
  18. // rightTop
  19. // right (center)
  20. // rightBottom
  21. // bottomRightCorner
  22. // bottomRight
  23. // bottom (center)
  24. // bottomLeft
  25. // bottomLeftCorner
  26. // leftBottom
  27. // left (center)
  28. // leftTop
  29. placement: "bottom",
  30.  
  31. // Determine whether to re-position the icon picker
  32. collision: "none",
  33.  
  34. // Enable animation
  35. animation: true,
  36.  
  37. // Hide the icon picker on select
  38. hideOnSelect: false,
  39.  
  40. // Show popover footer
  41. showFooter: false,
  42.  
  43. // Place the search filed in the footer
  44. searchInFooter: false,
  45.  
  46. // Pick the icon when click the accept button in the footer
  47. mustAccept: false,
  48.  
  49. // CSS class for the selected icon
  50. selectedCustomClass: "bg-primary",
  51.  
  52. // List of icon objects
  53. icons: [],
  54.  
  55. // Custom class formatter
  56. fullClassFormatter: function (e) {
  57. return e;
  58. },
  59.  
  60. // Input selector
  61. input: "input,.iconpicker-input",
  62.  
  63. // Determine whether to use this the input as a search box
  64. inputSearch: false,
  65.  
  66. // Append the icon picker to a specific element
  67. container: false,
  68.  
  69. // Default selector
  70. component: ".input-group-addon,.iconpicker-component",
  71.  
  72. // Customize the template here
  73. templates: {
  74. popover: '<div class="iconpicker-popover popover" role="tooltip"><div class="arrow"></div>' + '<div class="popover-title"></div><div class="popover-content"></div></div>',
  75. footer: '<div class="popover-footer"></div>',
  76. buttons: '<button class="iconpicker-btn iconpicker-btn-cancel btn btn-default btn-sm">Cancel</button>' + ' <button class="iconpicker-btn iconpicker-btn-accept btn btn-primary btn-sm">Accept</button>',
  77. search: '<input type="search" class="form-control iconpicker-search" placeholder="Type to filter" />',
  78. iconpicker: '<div class="iconpicker"><div class="iconpicker-items"></div></div>',
  79. iconpickerItem: '<a role="button" href="javascript:;" class="iconpicker-item"><i></i></a>'
  80. }
  81.  
  82. });

预览截图