2019独角兽企业重金招聘Python工程师标准>>>

  经常看到别人的博客里面有动态的云标签页,感觉很是高大上,自己也很像弄一个。于是去找寻源码,在阿里西西页面特效中找到了云标签的源码,经过分析和解剖,弄成了符合博客园的js.

  首先,找到博客园页面的管理界面

  在其中加入以下代码:

<style type="text/css">
#div1 {position:relative; width:200px; height:150px; margin: 2px auto 0; }
#div1 a {position:absolute; top:0px; left:0px; font-family: Microsoft YaHei; color:#fff; font-weight:bold; text-decoration:none; padding: 1px 2px; }
#div1 a:hover {border: 1px solid #eee; background: #000; }
#div1 .blue {color:blue;}
#div1 .red {color:red;}
#div1 .yellow {color:yellow;}
#div1 .green {color:green;}</style><script type="text/javascript">
var radius = 60;
var dtr = Math.PI/180;
var d=300;var mcList = [];
var active = false;
var lasta = 1;
var lastb = 1;
var distr = true;
var tspeed=10;
var size=200;var mouseX=0;
var mouseY=0;var howElliptical=1;var aA=null;
var oDiv=null;window.onload=function ()
{var i=0;var oTag=null;oDiv=document.getElementById('div1');aA=oDiv.getElementsByTagName('a');for(i=0;i<aA.length;i++){oTag={};oTag.offsetWidth=aA[i].offsetWidth;oTag.offsetHeight=aA[i].offsetHeight;mcList.push(oTag);}sineCosine( 0,0,0 );positionAll();oDiv.onmouseover=function (){active=true;};oDiv.onmouseout=function (){active=false;};oDiv.onmousemove=function (ev){var oEvent=window.event || ev;mouseX=oEvent.clientX-(oDiv.offsetLeft+oDiv.offsetWidth/2);
        mouseY=oEvent.clientY-(oDiv.offsetTop+oDiv.offsetHeight/2);
        mouseX/=5;
        mouseY/=5;
    };setInterval(update, 30);
};function update()
{var a;var b;if(active){a = (-Math.min( Math.max( -mouseY, -size ), size ) / radius ) * tspeed;b = (Math.min( Math.max( -mouseX, -size ), size ) / radius ) * tspeed;}else{a = lasta * 0.98;b = lastb * 0.98;}lasta=a;lastb=b;if(Math.abs(a)<=0.01 && Math.abs(b)<=0.01){return;}var c=0;sineCosine(a,b,c);for(var j=0;j<mcList.length;j++){var rx1=mcList[j].cx;var ry1=mcList[j].cy*ca+mcList[j].cz*(-sa);var rz1=mcList[j].cy*sa+mcList[j].cz*ca;var rx2=rx1*cb+rz1*sb;var ry2=ry1;var rz2=rx1*(-sb)+rz1*cb;var rx3=rx2*cc+ry2*(-sc);var ry3=rx2*sc+ry2*cc;var rz3=rz2;mcList[j].cx=rx3;mcList[j].cy=ry3;mcList[j].cz=rz3;per=d/(d+rz3);
        mcList[j].x=(howElliptical*rx3*per)-(howElliptical*2);mcList[j].y=ry3*per;mcList[j].scale=per;mcList[j].alpha=per;mcList[j].alpha=(mcList[j].alpha-0.6)*(10/6);
    }doPosition();depthSort();
}function depthSort()
{var i=0;var aTmp=[];for(i=0;i<aA.length;i++){aTmp.push(aA[i]);}aTmp.sort(function (vItem1, vItem2){if(vItem1.cz>vItem2.cz){return -1;}else if(vItem1.cz<vItem2.cz){return 1;}else{return 0;}});for(i=0;i<aTmp.length;i++){aTmp[i].style.zIndex=i;}
}function positionAll()
{var phi=0;var theta=0;var max=mcList.length;var i=0;var aTmp=[];var oFragment=document.createDocumentFragment();//随机排序for(i=0;i<aA.length;i++){aTmp.push(aA[i]);}aTmp.sort(function (){return Math.random()<0.5?1:-1;});for(i=0;i<aTmp.length;i++){oFragment.appendChild(aTmp[i]);}oDiv.appendChild(oFragment);for( var i=1; i<max+1; i++){if( distr ){phi = Math.acos(-1+(2*i-1)/max);
            theta = Math.sqrt(max*Math.PI)*phi;}else{phi = Math.random()*(Math.PI);theta = Math.random()*(2*Math.PI);}//坐标变换
        mcList[i-1].cx = radius * Math.cos(theta)*Math.sin(phi);mcList[i-1].cy = radius * Math.sin(theta)*Math.sin(phi);mcList[i-1].cz = radius * Math.cos(phi);aA[i-1].style.left=mcList[i-1].cx+oDiv.offsetWidth/2-mcList[i-1].offsetWidth/2+'px';aA[i-1].style.top=mcList[i-1].cy+oDiv.offsetHeight/2-mcList[i-1].offsetHeight/2+'px';}
}function doPosition()
{var l=oDiv.offsetWidth/2;var t=oDiv.offsetHeight/2;for(var i=0;i<mcList.length;i++){aA[i].style.left=mcList[i].cx+l-mcList[i].offsetWidth/2+'px';
        aA[i].style.top=mcList[i].cy+t-mcList[i].offsetHeight/2+'px';
        aA[i].style.fontSize=Math.ceil(12*mcList[i].scale/2)+8+'px';
        aA[i].style.filter="alpha(opacity="+100*mcList[i].alpha+")";aA[i].style.opacity=mcList[i].alpha;}
}function sineCosine( a, b, c)
{sa = Math.sin(a * dtr);ca = Math.cos(a * dtr);sb = Math.sin(b * dtr);cb = Math.cos(b * dtr);sc = Math.sin(c * dtr);cc = Math.cos(c * dtr);
}
</script><font face="Comic Sans MS"><strong><a href="http://weibo.com/u/3209909971/home?wvr=5&lf=reg">我的标签</a>
</strong></font><hr />
<div id="div1"><a href="http://www.cnblogs.com/xing901022/p/3694709.html"class="blue">2014</a><a href="http://www.cnblogs.com/xing901022/p/3248913.html"class="red">2013下</a><a href="http://www.cnblogs.com/xing901022/archive/2013/01/18/2857982.html" class="red">2013上</a><a href="http://www.cnblogs.com/xing901022/archive/2012/10/19/2699162.html" class="red">2012下</a><a href="http://zh.linuxvirtualserver.org/" class="green">LVS中文</a><a href="http://code.taobao.org/" class="green">开源</a><a href="http://www.cnblogs.com/xing901022/archive/2013/04/09/3248870.html" class="blue">反向代理</a><a href="http://www.cnblogs.com/xing901022/p/3248469.html" class="blue">CUDA</a>
</div>

代码分析

  以上源码,就可以直接在你的博客园ID上面显示云标签了

  那么我们分析以下,上面的代码:

  这个部分的代码,应该是直接嵌入到body里面的,所以引用的css js都要加入标签,下面是css的代码:

<style type="text/css">
#div1 {position:relative; width:200px; height:150px; margin: 2px auto 0; }
#div1 a {position:absolute; top:0px; left:0px; font-family: Microsoft YaHei; color:#fff; font-weight:bold; text-decoration:none; padding: 1px 2px; }
#div1 a:hover {border: 1px solid #eee; background: #000; }
#div1 .blue {color:blue;}
#div1 .red {color:red;}
#div1 .yellow {color:yellow;}
#div1 .green {color:green;}
</style>

  这里面的div是我们下面将要用到的标签内容div的id,通过这个id就可以引用到这里面的样式。

  上面最重要的一个参数

#div1 {position:relative; width:200px; height:150px; margin: 2px auto 0; }

  这段代码定义了云标签插件div的宽度和高度,调整适当的像素值,适应你的博客即可。

  下面是js的代码,radius定义了云标签的半径,可以通过设置该值,调整云标签的旋转半径,也就是球形的大小

<script type="text/javascript">
var radius = 60;
var dtr = Math.PI/180;
var d=300;var mcList = [];
var active = false;
var lasta = 1;
var lastb = 1;
var distr = true;
var tspeed=10;
var size=200;var mouseX=0;
var mouseY=0;var howElliptical=1;var aA=null;
var oDiv=null;window.onload=function ()
{var i=0;var oTag=null;oDiv=document.getElementById('div1');aA=oDiv.getElementsByTagName('a');for(i=0;i<aA.length;i++){oTag={};oTag.offsetWidth=aA[i].offsetWidth;oTag.offsetHeight=aA[i].offsetHeight;mcList.push(oTag);}sineCosine( 0,0,0 );positionAll();oDiv.onmouseover=function (){active=true;};oDiv.onmouseout=function (){active=false;};oDiv.onmousemove=function (ev){var oEvent=window.event || ev;mouseX=oEvent.clientX-(oDiv.offsetLeft+oDiv.offsetWidth/2);
        mouseY=oEvent.clientY-(oDiv.offsetTop+oDiv.offsetHeight/2);
        mouseX/=5;
        mouseY/=5;
    };setInterval(update, 30);
};function update()
{var a;var b;if(active){a = (-Math.min( Math.max( -mouseY, -size ), size ) / radius ) * tspeed;b = (Math.min( Math.max( -mouseX, -size ), size ) / radius ) * tspeed;}else{a = lasta * 0.98;b = lastb * 0.98;}lasta=a;lastb=b;if(Math.abs(a)<=0.01 && Math.abs(b)<=0.01){return;}var c=0;sineCosine(a,b,c);for(var j=0;j<mcList.length;j++){var rx1=mcList[j].cx;var ry1=mcList[j].cy*ca+mcList[j].cz*(-sa);var rz1=mcList[j].cy*sa+mcList[j].cz*ca;var rx2=rx1*cb+rz1*sb;var ry2=ry1;var rz2=rx1*(-sb)+rz1*cb;var rx3=rx2*cc+ry2*(-sc);var ry3=rx2*sc+ry2*cc;var rz3=rz2;mcList[j].cx=rx3;mcList[j].cy=ry3;mcList[j].cz=rz3;per=d/(d+rz3);
        mcList[j].x=(howElliptical*rx3*per)-(howElliptical*2);mcList[j].y=ry3*per;mcList[j].scale=per;mcList[j].alpha=per;mcList[j].alpha=(mcList[j].alpha-0.6)*(10/6);
    }doPosition();depthSort();
}function depthSort()
{var i=0;var aTmp=[];for(i=0;i<aA.length;i++){aTmp.push(aA[i]);}aTmp.sort(function (vItem1, vItem2){if(vItem1.cz>vItem2.cz){return -1;}else if(vItem1.cz<vItem2.cz){return 1;}else{return 0;}});for(i=0;i<aTmp.length;i++){aTmp[i].style.zIndex=i;}
}function positionAll()
{var phi=0;var theta=0;var max=mcList.length;var i=0;var aTmp=[];var oFragment=document.createDocumentFragment();//随机排序for(i=0;i<aA.length;i++){aTmp.push(aA[i]);}aTmp.sort(function (){return Math.random()<0.5?1:-1;});for(i=0;i<aTmp.length;i++){oFragment.appendChild(aTmp[i]);}oDiv.appendChild(oFragment);for( var i=1; i<max+1; i++){if( distr ){phi = Math.acos(-1+(2*i-1)/max);
            theta = Math.sqrt(max*Math.PI)*phi;}else{phi = Math.random()*(Math.PI);theta = Math.random()*(2*Math.PI);}//坐标变换
        mcList[i-1].cx = radius * Math.cos(theta)*Math.sin(phi);mcList[i-1].cy = radius * Math.sin(theta)*Math.sin(phi);mcList[i-1].cz = radius * Math.cos(phi);aA[i-1].style.left=mcList[i-1].cx+oDiv.offsetWidth/2-mcList[i-1].offsetWidth/2+'px';aA[i-1].style.top=mcList[i-1].cy+oDiv.offsetHeight/2-mcList[i-1].offsetHeight/2+'px';}
}function doPosition()
{var l=oDiv.offsetWidth/2;var t=oDiv.offsetHeight/2;for(var i=0;i<mcList.length;i++){aA[i].style.left=mcList[i].cx+l-mcList[i].offsetWidth/2+'px';
        aA[i].style.top=mcList[i].cy+t-mcList[i].offsetHeight/2+'px';
        aA[i].style.fontSize=Math.ceil(12*mcList[i].scale/2)+8+'px';
        aA[i].style.filter="alpha(opacity="+100*mcList[i].alpha+")";aA[i].style.opacity=mcList[i].alpha;}
}function sineCosine( a, b, c)
{sa = Math.sin(a * dtr);ca = Math.cos(a * dtr);sb = Math.sin(b * dtr);cb = Math.cos(b * dtr);sc = Math.sin(c * dtr);cc = Math.cos(c * dtr);
}
</script>

  最后添加自己的云标签内容,即可,后面的class会调用上面css定义的样式,如果没有自己喜欢的颜色或者样式,自己定义就行了。

<div id="div1"><a href="http://www.cnblogs.com/xing901022/p/3694709.html"class="blue">2014</a><a href="http://www.cnblogs.com/xing901022/p/3248913.html"class="red">2013下</a><a href="http://www.cnblogs.com/xing901022/archive/2013/01/18/2857982.html" class="red">2013上</a><a href="http://www.cnblogs.com/xing901022/archive/2012/10/19/2699162.html" class="red">2012下</a><a href="http://zh.linuxvirtualserver.org/" class="green">LVS中文</a><a href="http://code.taobao.org/" class="green">开源</a><a href="http://www.cnblogs.com/xing901022/archive/2013/04/09/3248870.html" class="blue">反向代理</a><a href="http://www.cnblogs.com/xing901022/p/3248469.html" class="blue">CUDA</a>
</div>

祝您的博客越来越漂亮。

转载于:https://my.oschina.net/u/204616/blog/545073

一分钟教你在博客园中制作自己的动态云球形标签页相关推荐

  1. wget ip_10分钟搭建个人开源博客+域名ip解析

    有多少人有进行搭建个人的开源博客呢? 个人博客在咱们日常的工作中,以及在面试的时候都是加分项,不管是自己写的,还是用开源系统的都算. 一个博客从0到上线,到外部别人可以访问,经过多个步骤,比如选购云服 ...

  2. 转载:如何快速转载CSDN及博客园中的博客

    原文:https://blog.csdn.net/qq_29796317/article/details/60975207 如何快速转载CSDN及博客园中的博客 前言   对于喜欢逛CSDN的人来说, ...

  3. 【转】博客园中应用LaTex进行公式编写

    在博客园中应用LaTex进行公式编写.切换到HTML编辑界面,加入如下语句: <img src="http://latex.codecogs.com/gif.latex?\sqrt{a ...

  4. 解决博客园中代码着色问题

    解决博客园中代码着色问题 参考文章: (1)解决博客园中代码着色问题 (2)https://www.cnblogs.com/mushan/p/3351594.html 备忘一下.

  5. 如何在博客园中自定义背景

    首先进入博客设置 然后在页面Css代码里将以下代码粘贴进去! 1 /*simplememory*/2 #google_ad_c1, #google_ad_c2 {display:none;}3 .sy ...

  6. 如何屏蔽博客园中的Google广告

    博客园中每篇文章的评论窗口最下面就带了一个Google的广告,当然我这个博客也不例外.不过这些广告我看着就不爽,于是就想办法把该死的广告去掉.使用Mathon2打开博客园中的任何一篇文章,选定Goog ...

  7. 一步一步教你自定义博客园(cnblog)界面

    一步一步教你自定义博客园(cnblog)界面 一.总结 二.一步一步教你自定义博客园(cnblog)界面 写在开头 我之前在博客园没怎么发东西,就是觉得博客园的Markdown不支持实时预览,加上ma ...

  8. 简单个人博客系统java web_JavaWeb个人博客项目:手把手教你实现博客后台系统之登录与注册...

    JavaWeb个人博客项目:手把手教你实现博客后台系统之登录与注册 发布时间:2020-07-17 17:10阅读:( )字号: 大 中 小 后台系统的所有界面图以及之前的准备工作欢迎看我之前的博文& ...

  9. 【经验】博客|使用 dotnet-cnblog 将Gitee图床的图片、本地的图片上传到博客园中

    若在Gitee图床,需要克隆到当前目录下,本质上其实还是上传本地图片到博客园中. 使用工具dotnet-cnblogs. 参考:博客园 Markdown 图片本地上传工具发布新版了. 该工具开源,源代 ...

  10. 群晖如何建php网站_折腾群晖笔记:使用群晖自带的web功能 五分钟搭建typecho个人博客...

    折腾群晖笔记:使用群晖自带的web功能 五分钟搭建typecho个人博客 2019-07-05 08:30:00 118点赞 735收藏 118评论 你是AMD Yes党?还是intel和NVIDIA ...

最新文章

  1. html实现以秒为单位倒数,跳转新的页面
  2. js中怎么为同级元素添加点击事件
  3. Linux 0.00 代码解析(一)
  4. 销毁AWS资源:Cloud-Nuke还是AWS-Nuke?
  5. WinForm UI设计与开发思路(转)
  6. leetcode 1486. 数组异或操作(位运算)
  7. libevent book——event | Gaccob的博客
  8. c语言词典课程设计报告,C语言课程设计英语词典排版系统
  9. C++11 处理时间和日期的处理,以及chrono库介绍
  10. 交换机的VLAN与Trunk配置
  11. 68超标量流水线的基本概念
  12. 深度学习中的常用的归一化方法汇总
  13. 鸡汤来了,成为数据分析师的快速指南
  14. MATLAB之fprintf
  15. 数据链路层-1 什么是数据链路层和工作原理
  16. 多行文字显示不完用省略号表示
  17. 庆祝自己喜提ROG冰刃3新锐!
  18. Angular 4 学习笔记1
  19. Mac翻译神器Mate Translate,支持超100种语言,读不准还可以照拼音念呦!
  20. fpga的希尔伯特变换实现

热门文章

  1. think in java 读书笔记 1 ——移位
  2. 使用jquery获取父元素或父节点的方法
  3. 【Matlab学习笔记】【函数学习】一(延时函数pause)
  4. 计算机领域顶级会议、期刊、人物与国家排名2019
  5. Python 读取MODIS叶绿素-a浓度.nc文件
  6. 详细解读二叉树基本操作
  7. SQLGrammarException :could not execute query a.user not exists解决
  8. Flink 在米哈游的落地实践
  9. 2019 年度全球程序员薪酬报告:40岁以后普遍遭遇收入天花板
  10. 10个小技巧:快速用Python进行数据分析