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


Posted in HTML / CSS onNovember 18, 2013

今天给大家带来一款超酷的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);
}
HTML / CSS 相关文章推荐
利用CSS3实现动态的二级三级菜单效果实例源码
Jan 04 HTML / CSS
纯CSS3打造动感漂亮时尚的扇形菜单
Mar 18 HTML / CSS
CSS3网格的三个新特性详解
Apr 04 HTML / CSS
CSS3实现瀑布流布局与无限加载图片相册的实例代码
Dec 22 HTML / CSS
如何用border-image实现文字气泡边框的示例代码
Jan 21 HTML / CSS
html5新增的定时器requestAnimationFrame实现进度条功能
Dec 13 HTML / CSS
HTML5中div、article、section的区别及使用介绍
Aug 14 HTML / CSS
谷歌浏览器小字体处理方案即12px以下字体
Dec 17 HTML / CSS
全面解析HTML5中的标准属性与自定义属性
Feb 18 HTML / CSS
详解HTML5常用的语义化标签
Sep 27 HTML / CSS
html form表单基础入门案例讲解
Jul 21 HTML / CSS
CSS 左边固定宽右边自适应的6种方法
May 15 HTML / CSS
CSS3 :nth-child()伪类选择器实现奇偶行显示不同样式
Nov 05 #HTML / CSS
css3实现图片遮罩效果鼠标hover以后出现文字
Nov 05 #HTML / CSS
css3的transition效果和transfor效果示例介绍
Oct 30 #HTML / CSS
CSS3之多背景background使用示例
Oct 18 #HTML / CSS
CSS3之背景尺寸Background-size使用介绍
Oct 14 #HTML / CSS
CSS3之边框多颜色Border-color属性使用示例
Oct 11 #HTML / CSS
CSS3文本换行word-wrap解决英文文本超过固定宽度不换行
Oct 10 #HTML / CSS
You might like
windows xp下安装pear
2006/12/02 PHP
用PHP实现维护文件代码
2007/06/14 PHP
thinkPHP订单数字提醒功能的实现方法
2016/12/01 PHP
Yii输入正确验证码却验证失败的解决方法
2017/06/06 PHP
PHP实现用session来实现记录用户登陆信息
2018/10/15 PHP
JQuery 初体验(建议学习jquery)
2009/04/25 Javascript
基于jquery实现的类似百度搜索的输入框自动完成功能
2011/08/23 Javascript
jQuery.extend 函数详解
2012/02/03 Javascript
九种js弹出对话框的方法总结
2013/03/12 Javascript
深入浅析react native es6语法
2015/12/09 Javascript
使用vue.js编写蓝色拼图小游戏
2017/03/17 Javascript
JavaScript纯色二维码变成彩色二维码
2020/07/23 Javascript
echarts学习笔记之图表自适应问题详解
2017/11/22 Javascript
原生JS实现旋转轮播图+文字内容切换效果【附源码】
2018/09/29 Javascript
vue.js实现回到顶部动画效果
2019/07/31 Javascript
关于layui 弹出层一闪而过就消失的解决方法
2019/09/09 Javascript
关于layui 下拉列表的change事件详解
2019/09/20 Javascript
解决layui table表单提示数据接口请求异常的问题
2019/09/24 Javascript
[05:36]DOTA2 2015国际邀请赛中国区预选赛第四日TOP10
2015/05/29 DOTA
wxpython中Textctrl回车事件无效的解决方法
2016/07/21 Python
用tensorflow搭建CNN的方法
2018/03/05 Python
Python  unittest单元测试框架的使用
2018/09/08 Python
python利用thrift服务读取hbase数据的方法
2018/12/27 Python
详解Python中is和==的区别
2019/03/21 Python
在 Windows 下搭建高效的 django 开发环境的详细教程
2020/07/27 Python
canvas绘制树形结构可视图形的实现
2020/04/03 HTML / CSS
戴尔加拿大官网:Dell加拿大
2016/09/17 全球购物
俄罗斯化妆品和香水网上商店:Iledebeaute
2019/01/03 全球购物
英语自我介绍演讲稿
2014/09/01 职场文书
协商一致解除劳动合同协议书
2014/09/14 职场文书
党支部四风整改方案
2014/10/25 职场文书
合作意向协议书
2015/01/29 职场文书
世界上超棒的8种逻辑思维
2019/08/06 职场文书
2019年自助餐厅创业计划书模板
2019/08/22 职场文书
python 使用tkinter与messagebox写界面和弹窗
2022/03/20 Python
Python如何利用pandas读取csv数据并绘图
2022/07/07 Python