html的标签代码悬停,HTML5 标签云+悬停放大发散动效

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

~ function() {

'use strict';

var spans = [],

screen = document.getElementById("screen"),

text = "";

document.currentScript.text.split(/[\s,.=>

if (w.length > 1) text += w + " ";

});

var CObj = function(elem) {

this.elem = elem;

this.x = elem.offsetLeft;

this.y = elem.offsetTop;

this.zooming = false;

this.scale = 1;

}

CObj.prototype.init = function() {

this.elem.obj = this;

this.elem.className = 'word';

this.elem.style.left = this.x + "px";

this.elem.style.top = this.y + "px";

this.glow = document.createElement("span");

this.glow.innerHTML = this.elem.innerHTML;

this.glow.className = "wordZoom";

screen.appendChild(this.glow);

this.glow.style.left = this.x + "px";

this.glow.style.top = this.y + "px";

}

CObj.prototype.start = function() {

if (!this.zooming) {

this.elem.className = "word over";

this.zooming = true;

this.glow.style.visibility = "visible";

}

}

CObj.prototype.zoom = function() {

if (this.zooming) {

this.scale *= 1.05;

if (this.scale < 20) {

var c = 512 - this.scale * 20;

this.glow.style.transform = this.glow.style.webkitTransform = "scale(" + this.scale + ")";

this.glow.style.color = "rgb(" + Math.round(c * .5) + "," + Math.round(c * .5) + "," + Math.round(c) + ")";

} else {

this.zooming = false;

this.scale = 1;

this.glow.style.transform = this.glow.style.webkitTransform = "scale(1)";

this.glow.style.visibility = "hidden";

this.elem.className = "word";

}

}

}

text += " ... ";

var comp = "",

word = "",

tag = false;

for (var i = 0; i < text.length; i++) {

var c = text.charAt(i);

if (c == "

var j = text.indexOf(">", i);

word += text.substring(i, j + 1);

i = j;

tag = true;

} else {

if (c == " ") {

if (tag) {

comp += word + "  ";

tag = false;

} else {

comp += "" + word + "  ";

}

word = "";

} else word += c;

}

}

screen.innerHTML = comp;

var n = screen.getElementsByTagName("*");

for (var i = 0; i < n.length; i++) {

var word = n[i];

spans[i] = new CObj(word);

}

for (var i = 0; i < spans.length; i++) {

spans[i].init();

}

screen.onmouseover = function(e) {

e.preventDefault();

if (e.target.obj) e.target.obj.start();

};

var run = function() {

requestAnimationFrame(run);

for (var i = 0; i < spans.length; i++) {

spans[i].zoom();

}

};

run();

}();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值