1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| (function (window, document, undefined) { var currentWords = []; var words = ["武汉大学", "自强", "弘毅", "求是", "拓新", "遥感信息工程学院", "笃志", "敦行", "和协", "拓新"]; var index = 0;
window.requestAnimationFrame = (function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { setTimeout(callback, 1000 / 60); } })();
init();
function init() { css(".float-word{z-index:9999;font-size:0.8em;position:fixed;font-weight:bold;user-select:none;}") attachEvent(); gameloop(); }
function gameloop() { for (var i = 0; i < currentWords.length; i++) { if (currentWords[i].alpha <= 0) { document.body.removeChild(currentWords[i].el); currentWords.splice(i, 1); continue; } currentWords[i].y--; currentWords[i].scale += 0.004; currentWords[i].alpha -= 0.013; currentWords[i].el.style.cssText = "left:" + currentWords[i].x + "px;top:" + currentWords[i].y + "px;opacity:" + currentWords[i].alpha + ";transform:scale(" + currentWords[i].scale + "," + currentWords[i].scale + ");color:" + currentWords[i].color; } requestAnimationFrame(gameloop); }
function attachEvent() { var old = typeof window.onclick === "function" && window.onclick; window.onclick = function (event) { old && old(); createHeart(event); } }
function createHeart(event) { var d = document.createElement("div"); d.className = 'float-word'; d.innerText = words[index++ % words.length] currentWords.push({ el: d, x: event.clientX - 5, y: event.clientY - 5, scale: 1, alpha: 1, color: randomColor() }); document.body.appendChild(d); }
function css(css) { var style = document.createElement("style"); style.type = "text/css"; try { style.appendChild(document.createTextNode(css)); } catch (ex) { style.styleSheet.cssText = css; } document.getElementsByTagName('head')[0].appendChild(style); }
function randomColor() { return "rgb(" + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + ")"; } })(window, document);
|