欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

一款超酷的js+css3实现的3D标签云特效兼容ie7/8/9

程序员文章站 2023-11-10 14:20:28
一款超酷的js+css3实现的3D标签云特效,兼容ie7/8/9,看惯了flash的,来试试这个吧,下面有个不错的示例,希望大家不要错过... 13-11-18...

今天给大家带来一款超酷的js+css3实现的3d标签云特效,

看惯了flash的,来试试这个吧。

ie7,8,9兼容哦~

html如下:

复制代码
代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta http-equiv="x-ua-compatible" content="ie=7" />
<title>超酷的js+css3实现的3d标签云特效,前端爱好者www.250ba.com</title>
<style>
body{ font-family:"微软雅黑", arial, sans-serif;} #main{border:none; background:none;}
body,ul,li,h1,h2,h3,p,form{margin:0;padding:0;}body{background:#fbfbfb;color:#444;font-size:14px;}</p> <p>a{color:#444;text-decoration:none;}a:hover{color:red;}</p> <p>#tagscloud{width:240px;height:250px;position:relative;font-size:12px;color:#333;margin:20px auto 0;text-align:center;}
#tagscloud a{position:absolute;top:0px;left:0px;color:#333;font-family:arial;text-decoration:none;}
#tagscloud a:hover{color:#fff;padding:5px;display:block;background:#d02f53;}
#tagscloud a.tagc1{margin:0 10px 15px 0;line-height:18px;width:65px;text-align:center;font-size:12px;padding:1px 5px;white-space:nowrap;display:inline-block;border-radius:3px;background:#666;color:#fff;}
#tagscloud a.tagc2{margin:0 10px 15px 0;line-height:18px;width:60px;text-align:center;font-size:12px;padding:1px 5px;white-space:nowrap;display:inline-block;border-radius:3px;background:#f16e50;color:#fff;}
#tagscloud a.tagc5{margin:0 10px 15px 0;line-height:18px;width:70px;text-align:center;font-size:12px;padding:1px 5px;white-space:nowrap;display:inline-block;border-radius:3px;background:#006633;color:#fff;}
</style>
</head>
<body>
<center>
<div style="font-size:15px; font-weight:bold; text-align:center; line-height:25px;">超酷的js+css3实现的3d标签云特效
</center>
<div id="tagscloud">
<a href="#" class="tagc1" title="星级评分">星级评分(2)</a>
<a href="#" class="tagc2" title="层特效">层特效(34)</a>
<a href="#" class="tagc5" title="关键字">关键字(8)</a>
<a href="#" class="tagc2" title="拖拽">拖拽(5)</a>
<a href="#"" class="tagc2" title="分页插件">分页插件(6)</a>
<a href="#" class="tagc1" title="时间插件">时间插件(9)</a>
<a href="#" class="tagc2" title="弹出层">弹出层(60)</a>
<a href="#" class="tagc5" title="数据统计">数据统计(2)</a>
<a href="#" class="tagc2" title="html5">html5(12)</a>
<a href="#" class="tagc2" title="置顶特效">置顶特效(5)</a>
<a href="#" class="tagc5" title="选项卡">选项卡(23)</a>
<a href="#" class="tagc2" title="导航菜单">导航菜单(31)</a>
<a href="#" class="tagc1" title="原创作品">原创作品(3)</a>
<a href="#" class="tagc2" title="动画插件">动画插件(15)</a>
<a href="#" class="tagc5" title="实用特效">实用特效(47)</a>
<a href="#" class="tagc2" title="table插件">table插件(1)</a>
<a href="#" class="tagc2" title="文字特效">文字特效(20)</a>
<a href="#" class="tagc5" title="图片特效">图片特效(61)</a>
<a href="#" class="tagc1" title="在线客服">在线客服(4)</a>
<a href="#" class="tagc2" title="瀑布流">瀑布流(10)</a>
<a href="#" class="tagc5" title="网友蘑菇">网友蘑菇(0)</a>
<a href="#" class="tagc2" title="网友嘿嘿">网友嘿嘿(3)</a>
<a href="#" class="tagc2" title="前端工具">前端工具(4)</a>
<a href="#" class="tagc2" title="网友adam">网友adam(15)</a>
<a href="#" class="tagc1" title="三级联动">三级联动(21)</a>
<a href="#" class="tagc2" title="颜色插件">颜色插件(4)</a>
<a href="#" class="tagc5" title="向导特效">向导特效(2)</a>
<a href="#" class="tagc2" title="自动补全">自动补全(5)</a>
<a href="#" class="tagc1" title="滚动特效">滚动特效(22)</a>
<a href="#" class="tagc5" title="提示插件">提示插件(24)</a>
</div></p> <p><script src='tagscloud.js' language='javascript'></script>
</body>
</html>

js代码如下(tagscloud.js):

复制代码
代码如下:

var radius = 90;
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('tagscloud');
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 = '#9933ff';
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;</p> <p>var rx2 = rx1 * cb + rz1 * sb;
var ry2 = ry1;
var rz2 = rx1 * (-sb) + rz1 * cb;</p> <p>var rx3 = rx2 * cc + ry2 * (-sc);
var ry3 = rx2 * sc + ry2 * cc;
var rz3 = rz2;</p> <p>mclist[i].cx = rx3;
mclist[i].cy = ry3;
mclist[i].cz = rz3;</p> <p>per = d / (d + rz3);</p> <p>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);</p> <p>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.fontsize=math.ceil(12*mclist[i].scale/2)+8+'px';
//aas.filter="progid:dximagetransform.microsoft.alpha(opacity="+100*mclist[i].alpha+")";
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);
}