标签云效果

<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>mathematic is so beautifull!</title>
    <meta name="author" content="hongru.chen" />
    <style type="text/css">
        html {overflow:hidden}
        body, .screen { overflow:hidden; width:100%; height:100%; position:absolute; margin:0; padding:0}
        #screen {left:0; top:0; zoom:1;}
        #screen a {position:absolute; font-size:12; overflow:hidden; padding:1px 2px; font-weight:bold;}
        #screen a:hover {border: 1px solid #ccc; background:#666}
    </style>
    <script type="text/javascript">
        var BeautifullMath = function () {
            var obj = [], xm = 0, ym = 0, axe = 0, aye = 0, parts = 50, scr,aArr, txe, tye, nw, nh;
            var colorArr = ['black','blue','red','green','yellow'];
            var addEvent = function (o, e, f) {
                window.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent('on'+e, function(){f.call(o)})
            }
            var resize = function () {
                nw = scr.offsetWidth * .5;
                nh = scr.offsetHeight * .5;
            }
            var init = function (id, f) {
                scr = document.getElementById(id);
                aArr = document.getElementsByTagName('a');
                addEvent(document, 'mousemove', function(e){
                    e = e || window.event;
                    xm = e.clientX;
                    ym = e.clientY;
                });
                resize();
                addEvent(window, 'resize', resize);
                __init(f);
                setInterval(run, 100);
            }
            var __init = function (f) {
                for (var i=0; i<aArr.length; i++) {
                    var o = {};
                    o.p = aArr[i];
                    o.p.style.color = colorArr[Math.round(Math.random()*4)];
                    var r = i/parts, j, a, b;
                    j = i % parts;
                    a = Math.floor(j)/200+(Math.floor(j/2)%10)/5* Math.PI * 2;
                    b = Math.acos(-0.9+(j%4)*0.6);
                    r = !!f?f(r):r-r*r+.5;
                    var sbr = Math.sin(b) * r;
                    o.x = Math.sin(a) * sbr;
                    o.y = Math.cos(a) * sbr;
                    o.z = Math.cos(b) * r;
                    obj.push(o);
                    o.transform = function () {
                        var ax = .02 * txe,
                            ay = .02 * tye,
                            cx = Math.cos(ax),
                            sx = Math.sin(ax),
                            cy = Math.cos(ay),
                            sy = Math.sin(ay);
//rotation
                        var z = this.y * sx + this.z * cx;
                        this.y = this.y * cx + this.z * -sx;
                        this.z = this.x * -sy + z * cy;
                        this.x = this.x * cy + z * sy;
//3d
                        var scale = 1 / (1 + this.z),
                            x = this.x * scale * nh + nw - scale * 2,
                            y = this.y * scale * nh + nh - scale * 2;
//set style
                        var p = this.p.style;
                        if (x >= 0 && y >=0 && x < nw * 2 && y < nh * 2) {
                            var c = Math.round(256 + (-this.z * 256));
                            p.left = Math.round(x) + 'px';
                            p.top = Math.round(y) + 'px';
                            p.fontSize = Math.round(12*scale) + 'px';
                            p.zIndex = 200 + Math.floor(-this.z * 100);
                            p.opacity = .6 - this.z;
                            p.filter = 'alpha(opacity='+100*(.6-this.z)+')';
                        } else p.width = "0px";
                    }
                }
            }
//run function
            var run = function () {
                var se = 1 / nh;
                txe = (ym - axe) * se;
                tye = (xm - aye) * se;
                axe += txe;
                aye += tye;
                /* ---- anim particles ---- */
                for (var i = 0, o; o = obj[i]; i++) o.transform();
            }
            return {init:init}
        }();
        onload = function () {
            BeautifullMath.init('screen', function(r){
                return .4;
            });
        }
    </script></head>
<body>
<div id="screen" class="screen">
    <a href="http://www.cnblogs.com/hongru/">JS</a>
    <a href="http://www.cnblogs.com/hongru/">JavaScript</a>
    <a href="http://www.cnblogs.com/hongru/">岑安</a>
    <a href="http://www.cnblogs.com/hongru/">博客园</a>
    <a href="http://www.cnblogs.com/hongru/">前端</a>
    <a href="http://www.cnblogs.com/hongru/">IE</a>
    <a href="http://www.cnblogs.com/hongru/">特效</a>
    <a href="http://www.cnblogs.com/hongru/">JavaScript</a>
    <a href="http://www.cnblogs.com/hongru/">FireFox</a>
    <a href="http://www.cnblogs.com/hongru/">CSS</a>
    <a href="http://www.cnblogs.com/hongru/">Chrome</a>
    <a href="http://www.cnblogs.com/hongru/">Google</a>
    <a href="http://www.cnblogs.com/hongru/">算法</a>
    <a href="http://www.cnblogs.com/hongru/">架构</a>
    <a href="http://www.cnblogs.com/hongru/">OOP</a>
    <a href="http://www.cnblogs.com/hongru/">XHTML</a>
    <a href="http://www.cnblogs.com/hongru/">setInterval</a>
    <a href="http://www.cnblogs.com/hongru/">W3C</a>
    <a href="http://www.cnblogs.com/hongru/">Hongru</a>
    <a href="http://www.cnblogs.com/hongru/">幻灯片</a>
</div>
</body>
</html>

转载于:https://my.oschina.net/yonghan/blog/844774

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值