HTML5标记云插件 JavaScript&jQuery TagCanvas

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

简介

TagCanvas是一个jQuery&Vanilla JavaScript插件,用于创建一个基于HTML5画布的标签云,并提供大量自定义选项。

特征:

  • 平滑动画。
  • 输入标记时播放声音。
  • 可拖动标记。
  • 与标记交互时暂停移动。
  • 自定义形状。

如何使用它:

1.在文档中加载TagCanvas库。

  1. <!-- Vanilla JS Version -->
  2. <script src="tagcanvas.min.js"></script>
  3.  
  4. <!-- jQuery Version -->
  5. <script src="/path/to/cdn/jquery.min.js"></script>
  6. <script src="jquery.tagcanvas.min.js"></script>

2.为标记云创建一个空的Canvas元素。

  1. <canvas id="myCanvas">
  2. ...
  3. </canvas>

3.创建一个标签链接列表,如下所示:

  1. <div id="tags">
  2. <ul>
  3. <li><a href="#">Tag 1</a></li>
  4. <li><a href="#">Tag 2</a></li>
  5. <li><a href="#">Tag 3</a></li>
  6. ... more tags here
  7. </ul>
  8. </div>

4.初始化插件并在您刚刚创建的HTML5画布元素上渲染标签云:

  1. // Vanilla JS Version
  2. TagCanvas.Start('myCanvas','tags',{
  3. // options here
  4. });
  5.  
  6. // jQuery Version
  7. $('#myCanvas').tagcanvas({
  8. // options here
  9. }, 'tags')

5.可用于自定义标签云的插件选项:

  1. {
  2. z1: 20000,
  3. z2: 20000,
  4. z0: 0.0002,
  5. freezeActive: false,
  6. freezeDecel: false,
  7. activeCursor: 'pointer',
  8. pulsateTo: 1,
  9. pulsateTime: 3,
  10. reverse: false,
  11. depth: 0.5,
  12. maxSpeed: 0.05,
  13. minSpeed: 0,
  14. decel: 0.95,
  15. interval: 20,
  16. minBrightness: 0.1,
  17. maxBrightness: 1,
  18. outlineColour: '#ffff99',
  19. outlineThickness: 2,
  20. outlineOffset: 5,
  21. outlineMethod: 'outline', // 'classic', 'block', 'colour', 'size', 'none'
  22. outlineRadius: 0,
  23. textColour: '#ff99ff',
  24. textHeight: 15,
  25. textFont: 'Helvetica, Arial, sans-serif',
  26. shadow: '#000',
  27. shadowBlur: 0,
  28. shadowOffset: [0,0],
  29. initial: null,
  30. hideTags: true,
  31. zoom: 1,
  32. weight: false,
  33. weightMode: 'size', // 'colour', 'both', 'bgcolour', 'bgoutline', 'outline'
  34. weightFrom: null,
  35. weightSize: 1,
  36. weightSizeMin: null,
  37. weightSizeMax: null,
  38. weightGradient: {0:'#f00', 0.33:'#ff0', 0.66:'#0f0', 1:'#00f'},
  39. txtOpt: true,
  40. txtScale: 2,
  41. frontSelect: false,
  42. wheelZoom: true,
  43. zoomMin: 0.3,
  44. zoomMax: 3,
  45. zoomStep: 0.05,
  46. shape: 'sphere', // 'vcylinder', 'hcylinder', 'hring', 'vring', ...
  47. // Limits rotation of the cloud using the mouse.
  48. // A value of "x" limits rotation to the x-axis, "y" limits rotation to the y-axis.
  49. // A value of "xy" will prevent the cloud rotating in response to the mouse - the cloud will only move if the initial option is used to give it a starting speed.
  50. lock: null,
  51. tooltip: null, // 'native' for operating system tooltips; 'div' for div-based.
  52. tooltipDelay: 300,
  53. tooltipClass: 'tctooltip',
  54. radiusX: 1,
  55. radiusY: 1,
  56. radiusZ: 1,
  57. stretchX: 1,
  58. stretchY: 1,
  59. offsetX: 0,
  60. offsetY: 0,
  61. shuffleTags: false,
  62. noSelect: false,
  63. noMouse: false,
  64. imageScale: 1,
  65. paused: false,
  66. dragControl: false,
  67. dragThreshold: 4,
  68. centreFunc: Nop,
  69. splitWidth: 0,
  70. animTiming: 'Smooth', // or 'Linear'
  71. clickToFront: false,
  72. fadeIn: 0,
  73. padding: 0,
  74. bgColour: null,
  75. bgRadius: 0,
  76. bgOutline: null,
  77. bgOutlineThickness: 0,
  78. outlineIncrease: 4,
  79. textAlign: 'centre', // 'left', 'right'
  80. textVAlign: 'middle', // 'top', 'bottom'
  81. imageMode: null, // 'image', 'text', 'both'
  82. imagePosition: null, // 'left', 'right', 'top', 'bottom'
  83. imagePadding: 2,
  84. imageAlign: 'centre', // 'left', 'right'
  85. imageVAlign: 'middle', // 'top', 'bottom'
  86. noTagsMessage: true,
  87. centreImage: null, // Uses a built-in centreFunc callback function to draw the image at full size in the middle of the canvas.
  88. pinchZoom: false,
  89. repeatTags: 0,
  90. minTags: 0,
  91. imageRadius: 0,
  92. scrollPause: false,
  93. outlineDash: 0,
  94. outlineDashSpace: 0,
  95. outlineDashSpeed: 1,
  96. activeAudio: '', // audio path
  97. audioVolume: 1,
  98. audioIcon: 1,
  99. audioIconSize: 20,
  100. audioIconThickness: 2,
  101. audioIconDark: 0,
  102. altImage: 0, // Set to true to swap to the second image in the element when the tag is active. }

 

6.API方法:

  1. // pause the animation
  2. TagCanvas.Pause(canvasId);
  3. $(selector).tagcanvas("pause");
  4. // resume the animation
  5. TagCanvas.Resume(canvasId);
  6. $(selector).tagcanvas("resume");
  7. // reload the tags
  8. TagCanvas.Reload(canvasId);
  9. $(selector).tagcanvas("reload");
  10. // update the tags
  11. TagCanvas.Update(canvasId);
  12. $(selector).tagcanvas("update");
  13. // bring a tag to the front of the cloud
  14. TagCanvas.TagToFront(canvasId, {
  15. id: "tag1",
  16. index: null, // Array index of tag to move to front
  17. text: null, // Text content of tag to move to front
  18. time: 500, // Duration of movement in milliseconds
  19. callback: null, // Function to call after movement has completed
  20. active: false, // If true, highlights the tag while it is in motion
  21. });
  22. $(selector).tagcanvas("tagtofront", {
  23. // TagToFront options here
  24. });
  25. // move a tag to another position
  26. TagCanvas.RotateTag(canvasId{
  27. id: "tag1",
  28. index: null, // Array index of tag to move to front
  29. text: null, // Text content of tag to move to front
  30. time: 500, // Duration of movement in milliseconds
  31. callback: null, // Function to call after movement has completed
  32. active: false, // If true, highlights the tag while it is in motion
  33. lat: null, // Latitude of destination
  34. lng: null, // Longitude of destination
  35. });
  36. $(selector).tagcanvas("rotatetag", {
  37. // RotateTag options here
  38. });
  39. // set the cloud speed and direction
  40. TagCanvas.SetSpeed(canvasId, [0.5, -0.25]);
  41. $(selector).tagcanvas("setspeed", [0.5, -0.25]);
  42. // remove the tag cloud
  43. TagCanvas.Delete(canvasId);
  44. $(selector).tagcanvas("delete");

更新日志:

v2.11.1版本(2022-03-10)

v2.9.0版本(2016-03-02)

v2.5.0版本(2014-07-04)

v2.4.0版本(2014-05-28)

v2.2.0版本(2013-07-08)

 

预览截图