响应式标记云(网格)插件 jQuery Wordbox

  • 源码大小:91.38KB
  • 所需积分:1积分
  • 源码编号:19JP-3278
  • 浏览次数:673次
  • 最后更新:2023年05月25日
  • 所属栏目:文本
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

Wordbox是一个很小的jQuery插件,它从JS数组中提取单词(标签),并将它们转换为响应二维网格风格的标签云。

标签云可以动态调整自身大小以适应给定的区域,并在每次重新加载页面时随机排列标签。

参见:

  • JavaScript中的10个最佳标记云生成器

如何使用它:

1.下载zip并在页面上包含Wordbox插件的文件。

  1. <!-- jQuery is required -->
  2. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  3.  
  4. <!-- jQuery Wordbox Plugin -->
  5. <link rel="stylesheet" href="/path/to/dist/wordbox.css" />
  6. <script src="/path/to/dist/wordbox.js"></script>

2.为标签云创建HTML。

  1. <div class="grid-wrap">
  2. <div id="myTagsCloud" class="wordbox"></div>
  3. </div>
  1. .grid-wrap {
  2. min-width: 400px;
  3. width: 100%;
  4. height: 400px;
  5. }

3.在JS数组中定义您的标签,如下所示:

  1. let words = [
  2. {
  3. 'title': 'jQueryScript',
  4. 'url': 'https://www.jqueryscript.net'
  5. },
  6. {
  7. 'title': 'CSSScript',
  8. 'url': 'https://www.cssscript.com'
  9. },
  10. // more tags here
  11. ]

4.定义JS数组中标签的背景颜色如下:

  1. let myColors = ['#F46779', '#045DA4']

5.初始化插件,在您刚刚创建的容器中生成一个响应标签云:

  1. let tc = new dodoroy.WordBox('#myTagsCloud', {
  2. words: words,
  3. colors: myColors,
  4. isFixedWidth: false,
  5. })

6.创建一个总是首先显示在标记云中的“前导”标记。

  1. let tc = new dodoroy.WordBox('#myTagsCloud', {
  2. words: words,
  3. colors: myColors,
  4. isFixedWidth: false,
  5. isLead: true,
  6. leadWord: {
  7. 'title': 'jQueryScript',
  8. 'url': 'https://www.jqueryscript.net/'
  9. },
  10. })

7.指定此标记云的宽度和高度。

  1. let tc = new dodoroy.WordBox('#myTagsCloud', {
  2. words: words,
  3. colors: myColors,
  4. isFixedWidth: true,
  5. width: 1000,
  6. height: 200,
  7. })

预览截图