Emlog非插件实现3D标签云

第一步

module找到你的侧边栏标签 修改侧边栏标签如下

  1. <?php
  2. //3D标签云
  3. function widget_tag($title){
  4. global $CACHE;
  5. $tag_cache = $CACHE->readCache('tags');?>
  6. <div class="side">
  7. <h3><i class="fa fa-tags mar-r-4"></i><?php echo $title;?></h3>
  8. <div id="tag_cloud_widget">
  9. <div class="tagcloud">
  10. <script type="text/javascript" src="<?php echo TEMPLATE_URL; ?>js/3dtag.js"></script>
  11. <?php foreach($tag_cache as $value): ?>
  12. <a href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇文章"><?php echo $value['tagname']; ?></a>
  13. <?php endforeach; ?>
  14. <div class="clear"></div></div></div></div>
  15. <?php }?>

第二步

你的公用模板css放如下css

  1. /*3D标签云*/
  2. #tag_cloud_widget{position:relative;width:240px;height:240px;margin:10px auto 10px}
  3. #tag_cloud_widget a{position:absolute;color:#fff;text-align:center;text-overflow:ellipsis;white-space:nowrap;top:0;left:0;padding:3px 5px;border:0}
  4. #tag_cloud_widget a:hover{background:#d02f53;display:block}
  5. #tag_cloud_widget a:nth-child(n){background:#666;border-radius:3px;display:inline-block;line-height:18px;margin:0 10px 15px 0}
  6. #tag_cloud_widget a:nth-child(2n){background:#d1a601}
  7. #tag_cloud_widget a:nth-child(3n){background:#286c4a}
  8. #tag_cloud_widget a:nth-child(5n){background:#518ab2}
  9. #tag_cloud_widget a:nth-child(4n){background:#c91d13}

第三步

保存下面js为3dtag.js 放到你的模板js目录里面

  1. var radius = 100;
  2. var d = 200;
  3. var dtr = Math.PI / 180;
  4. var mcList = [];
  5. var lasta = 1;
  6. var lastb = 1;
  7. var distr = true;
  8. var tspeed = 11;
  9. var size = 200;
  10. var mouseX = 0;
  11. var mouseY = 10;
  12. var howElliptical = 1;
  13. var aA = null;
  14. var oDiv = null;
  15. window.onload = function() {
  16. var i = 0;
  17. var oTag = null;
  18. oDiv = document.getElementById('tag_cloud_widget');
  19. aA = oDiv.getElementsByTagName('a');
  20. for (i = 0; i < aA.length; i++) {
  21. oTag = {};
  22. aA[i].onmouseover = (function(obj) {
  23. return function() {
  24. obj.on = true;
  25. this.style.zIndex = 9999;
  26. this.style.color = '#fff';
  27. this.style.background = '#0099ff';
  28. this.style.padding = '5px 5px';
  29. this.style.filter = "alpha(opacity=100)";
  30. this.style.opacity = 1
  31. }
  32. })(oTag) aA[i].onmouseout = (function(obj) {
  33. return function() {
  34. obj.on = false;
  35. this.style.zIndex = obj.zIndex;
  36. this.style.color = '#fff';
  37. this.style.background = '#30899B';
  38. this.style.padding = '5px';
  39. this.style.filter = "alpha(opacity=" + 100 * obj.alpha + ")";
  40. this.style.opacity = obj.alpha;
  41. this.style.zIndex = obj.zIndex
  42. }
  43. })(oTag) oTag.offsetWidth = aA[i].offsetWidth;
  44. oTag.offsetHeight = aA[i].offsetHeight;
  45. mcList.push(oTag)
  46. }
  47. sineCosine(0, 0, 0);
  48. positionAll(); (function() {
  49. update();
  50. setTimeout(arguments.callee, 40)
  51. })()
  52. };
  53. function update() {
  54. var a, b, c = 0;
  55. a = (Math.min(Math.max( - mouseY, -size), size) / radius) * tspeed;
  56. b = ( - Math.min(Math.max( - mouseX, -size), size) / radius) * tspeed;
  57. lasta = a;
  58. lastb = b;
  59. if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01) {
  60. return
  61. }
  62. sineCosine(a, b, c);
  63. for (var i = 0; i < mcList.length; i++) {
  64. if (mcList[i].on) {
  65. continue
  66. }
  67. var rx1 = mcList[i].cx;
  68. var ry1 = mcList[i].cy * ca + mcList[i].cz * ( - sa);
  69. var rz1 = mcList[i].cy * sa + mcList[i].cz * ca;
  70. var rx2 = rx1 * cb + rz1 * sb;
  71. var ry2 = ry1;
  72. var rz2 = rx1 * ( - sb) + rz1 * cb;
  73. var rx3 = rx2 * cc + ry2 * ( - sc);
  74. var ry3 = rx2 * sc + ry2 * cc;
  75. var rz3 = rz2;
  76. mcList[i].cx = rx3;
  77. mcList[i].cy = ry3;
  78. mcList[i].cz = rz3;
  79. per = d / (d + rz3);
  80. mcList[i].x = (howElliptical * rx3 * per) - (howElliptical * 2);
  81. mcList[i].y = ry3 * per;
  82. mcList[i].scale = per;
  83. var alpha = per;
  84. alpha = (alpha - 0.6) * (10 / 6);
  85. mcList[i].alpha = alpha * alpha * alpha - 0.2;
  86. mcList[i].zIndex = Math.ceil(100 - Math.floor(mcList[i].cz))
  87. }
  88. doPosition()
  89. }
  90. function depthSort() {
  91. var i = 0;
  92. var aTmp = [];
  93. for (i = 0; i < aA.length; i++) {
  94. aTmp.push(aA[i])
  95. }
  96. aTmp.sort(function(vItem1, vItem2) {
  97. if (vItem1.cz > vItem2.cz) {
  98. return - 1
  99. } else if (vItem1.cz < vItem2.cz) {
  100. return 1
  101. } else {
  102. return 0
  103. }
  104. });
  105. for (i = 0; i < aTmp.length; i++) {
  106. aTmp[i].style.zIndex = i
  107. }
  108. }
  109. function positionAll() {
  110. var phi = 0;
  111. var theta = 0;
  112. var max = mcList.length;
  113. for (var i = 0; i < max; i++) {
  114. if (distr) {
  115. phi = Math.acos( - 1 + (2 * (i + 1) - 1) / max);
  116. theta = Math.sqrt(max * Math.PI) * phi
  117. } else {
  118. phi = Math.random() * (Math.PI);
  119. theta = Math.random() * (2 * Math.PI)
  120. }
  121. mcList[i].cx = radius * Math.cos(theta) * Math.sin(phi);
  122. mcList[i].cy = radius * Math.sin(theta) * Math.sin(phi);
  123. mcList[i].cz = radius * Math.cos(phi);
  124. aA[i].style.left = mcList[i].cx + oDiv.offsetWidth / 2 - mcList[i].offsetWidth / 2 + 'px';
  125. aA[i].style.top = mcList[i].cy + oDiv.offsetHeight / 2 - mcList[i].offsetHeight / 2 + 'px'
  126. }
  127. }
  128. function doPosition() {
  129. var l = oDiv.offsetWidth / 2;
  130. var t = oDiv.offsetHeight / 2;
  131. for (var i = 0; i < mcList.length; i++) {
  132. if (mcList[i].on) {
  133. continue
  134. }
  135. var aAs = aA[i].style;
  136. if (mcList[i].alpha > 0.1) {
  137. if (aAs.display != '') aAs.display = ''
  138. } else {
  139. if (aAs.display != 'none') aAs.display = 'none';
  140. continue
  141. }
  142. aAs.left = mcList[i].cx + l - mcList[i].offsetWidth / 2 + 'px';
  143. aAs.top = mcList[i].cy + t - mcList[i].offsetHeight / 2 + 'px';
  144. aAs.filter = "alpha(opacity=" + 100 * mcList[i].alpha + ")";
  145. aAs.zIndex = mcList[i].zIndex;
  146. aAs.opacity = mcList[i].alpha
  147. }
  148. }
  149. function sineCosine(a, b, c) {
  150. sa = Math.sin(a * dtr);
  151. ca = Math.cos(a * dtr);
  152. sb = Math.sin(b * dtr);
  153. cb = Math.cos(b * dtr);
  154. sc = Math.sin(c * dtr);
  155. cc = Math.cos(c * dtr)
  156. }

猜你喜欢

转载自www.cnblogs.com/ggcg135/p/12040538.html
今日推荐