IT技术宅

青春是一个充满活力的季节,即便是我们失去了天使的翅膀,只要我们还有一颗青春的心,那么我们的生活依然能够如阳光般灿烂!......
现在位置:首页 > Emlog相关 > emlog彩色3D标签云 - 非插件

emlog彩色3D标签云 - 非插件

刘振兴     Emlog相关      2015年10月02日     4515     5条评论  

刚才在emlog模板中心有款新出的模板,进入了作者的主页,看上了它那个侧边上的3D标签云,看上去还是很不错的,就给扒了下来

本人菜鸟一枚,各位大大请轻喷,下面是使用上的效果,也可以看我的侧边,已经启用的

QQ截图20151002092812.png

是不是看上去还不错,下面来讲下实现过程

首先是css样式部分


/*标签云*/
#tag_cloud_widget{position:relative;width:240px;height:240px;margin:10px auto 10px}
#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}
#tag_cloud_widget a:hover{background:#d02f53;display:block}
#tag_cloud_widget a:nth-child(n){background:#666;border-radius:3px;display:inline-block;line-height:18px;margin:0 10px 15px 0}
#tag_cloud_widget a:nth-child(2n){background:#d1a601}
#tag_cloud_widget a:nth-child(3n){background:#286c4a}
#tag_cloud_widget a:nth-child(5n){background:#518ab2}
#tag_cloud_widget a:nth-child(4n){background:#c91d13}


然后是js部分


var radius = 100;
var d = 200;
var dtr = Math.PI / 180;
var mcList = [];
var lasta = 1;
var lastb = 1;
var distr = true;
var tspeed = 11;
var size = 200;
var mouseX = 0;
var mouseY = 10;
var howElliptical = 1;
var aA = null;
var oDiv = null;
window.onload = function() {
	var i = 0;
	var oTag = null;
	oDiv = document.getElementById('tag_cloud_widget');
	aA = oDiv.getElementsByTagName('a');
	for (i = 0; i < aA.length; i++) {
		oTag = {};
		aA[i].onmouseover = (function(obj) {
			return function() {
				obj.on = true;
				this.style.zIndex = 9999;
				this.style.color = '#fff';
				this.style.background = '#0099ff';
				this.style.padding = '5px 5px';
				this.style.filter = "alpha(opacity=100)";
				this.style.opacity = 1
			}
		})(oTag) aA[i].onmouseout = (function(obj) {
			return function() {
				obj.on = false;
				this.style.zIndex = obj.zIndex;
				this.style.color = '#fff';
				this.style.background = '#30899B';
				this.style.padding = '5px';
				this.style.filter = "alpha(opacity=" + 100 * obj.alpha + ")";
				this.style.opacity = obj.alpha;
				this.style.zIndex = obj.zIndex
			}
		})(oTag) oTag.offsetWidth = aA[i].offsetWidth;
		oTag.offsetHeight = aA[i].offsetHeight;
		mcList.push(oTag)
	}
	sineCosine(0, 0, 0);
	positionAll(); (function() {
		update();
		setTimeout(arguments.callee, 40)
	})()
};
function update() {
	var a, b, c = 0;
	a = (Math.min(Math.max( - mouseY, -size), size) / radius) * tspeed;
	b = ( - Math.min(Math.max( - mouseX, -size), size) / radius) * tspeed;
	lasta = a;
	lastb = b;
	if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01) {
		return
	}
	sineCosine(a, b, c);
	for (var i = 0; i < mcList.length; i++) {
		if (mcList[i].on) {
			continue
		}
		var rx1 = mcList[i].cx;
		var ry1 = mcList[i].cy * ca + mcList[i].cz * ( - sa);
		var rz1 = mcList[i].cy * sa + mcList[i].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[i].cx = rx3;
		mcList[i].cy = ry3;
		mcList[i].cz = rz3;
		per = d / (d + rz3);
		mcList[i].x = (howElliptical * rx3 * per) - (howElliptical * 2);
		mcList[i].y = ry3 * per;
		mcList[i].scale = per;
		var alpha = per;
		alpha = (alpha - 0.6) * (10 / 6);
		mcList[i].alpha = alpha * alpha * alpha - 0.2;
		mcList[i].zIndex = Math.ceil(100 - Math.floor(mcList[i].cz))
	}
	doPosition()
}
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;
	for (var i = 0; i < max; i++) {
		if (distr) {
			phi = Math.acos( - 1 + (2 * (i + 1) - 1) / max);
			theta = Math.sqrt(max * Math.PI) * phi
		} else {
			phi = Math.random() * (Math.PI);
			theta = Math.random() * (2 * Math.PI)
		}
		mcList[i].cx = radius * Math.cos(theta) * Math.sin(phi);
		mcList[i].cy = radius * Math.sin(theta) * Math.sin(phi);
		mcList[i].cz = radius * Math.cos(phi);
		aA[i].style.left = mcList[i].cx + oDiv.offsetWidth / 2 - mcList[i].offsetWidth / 2 + 'px';
		aA[i].style.top = mcList[i].cy + oDiv.offsetHeight / 2 - mcList[i].offsetHeight / 2 + 'px'
	}
}
function doPosition() {
	var l = oDiv.offsetWidth / 2;
	var t = oDiv.offsetHeight / 2;
	for (var i = 0; i < mcList.length; i++) {
		if (mcList[i].on) {
			continue
		}
		var aAs = aA[i].style;
		if (mcList[i].alpha > 0.1) {
			if (aAs.display != '') aAs.display = ''
		} else {
			if (aAs.display != 'none') aAs.display = 'none';
			continue
		}
		aAs.left = mcList[i].cx + l - mcList[i].offsetWidth / 2 + 'px';
		aAs.top = mcList[i].cy + t - mcList[i].offsetHeight / 2 + 'px';
		aAs.filter = "alpha(opacity=" + 100 * mcList[i].alpha + ")";
		aAs.zIndex = mcList[i].zIndex;
		aAs.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)
}


下面是php部分,修改module里的侧边标签方法

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

php函数可能和大家的有些不同,更具情况修改就行了,有什么问题可以QQ联系我,如果你最基础的都不会,那就别联系我了,先去看看教程

评论一下 分享本文 赞助本站 联系站长
IT技术宅
 挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论
Simplexity
Simplexity 2016-02-27 20:49 重庆市电信 回复
IT技术宅已经用上了,谢谢博主~
 Windows XP   Google Chrome 45.0.2454.85
wolf
wolf 2015-11-16 16:39 山东省济南市移动 回复
确实很漂亮....博主能做成插件分享下吗
IT技术宅好羞射,文章真的好赞啊,顶博主!
 Windows XP   TheWorld Browser
刘振兴
刘振兴2015-11-16 16:49 IANA保留地址回复
@wolf:别人的版权,也是比较简单的,代码都在上面,插件的话以后会考虑IT技术宅
 Windows 7   Maxthon 4.1.2.4000
金笔头博客
金笔头博客 2015-10-18 15:21 上海市电信 回复
好羡慕你的标签效果,等会我也试试IT技术宅
 Windows 7 x64   Google Chrome 45.0.2454.101
刘振兴
刘振兴2015-10-18 20:59 IANA保留地址回复
@金笔头博客:嗯嗯  挺简单的,有什么问题可以联系我IT技术宅
 Windows 10 x64   Google Chrome 45.0.2454.93