1/*! 2 * Fairy Dust Cursor.js 3 * - 90's cursors collection 4 * -- https://github.com/tholman/90s-cursor-effects 5 * -- http://codepen.io/tholman/full/jWmZxZ/ 6 */ 7 8//é¼ æ ç¹å»éªè±ç¹æ 9(function fairyDustCursor () { 10 11 var possibleColors = ["#D61C59", "#E7D84B", "#1B8798"] 12 var width = window.innerWidth; 13 var height = window.innerHeight; 14 var cursor = { x: width / 2, y: width / 2 }; 15 var particles = []; 16 17 function init () { 18 bindEvents(); 19 loop(); 20 } 21 22 // Bind events that are needed 23 function bindEvents () { 24 document.addEventListener('mousemove', onMouseMove); 25 document.addEventListener('touchmove', onTouchMove); 26 document.addEventListener('touchstart', onTouchMove); 27 28 window.addEventListener('resize', onWindowResize); 29 } 30 31 function onWindowResize (e) { 32 width = window.innerWidth; 33 height = window.innerHeight; 34 } 35 36 function onTouchMove (e) { 37 if (e.touches.length > 0) { 38 for (var i = 0; i < e.touches.length; i++) { 39 addParticle(e.touches[i].clientX, e.touches[i].clientY, possibleColors[Math.floor(Math.random() * possibleColors.length)]); 40 } 41 } 42 } 43 44 function onMouseMove (e) { 45 cursor.x = e.clientX; 46 cursor.y = e.clientY; 47 48 addParticle(cursor.x, cursor.y, possibleColors[Math.floor(Math.random() * possibleColors.length)]); 49 } 50 51 function addParticle (x, y, color) { 52 var particle = new Particle(); 53 particle.init(x, y, color); 54 particles.push(particle); 55 } 56 57 function updateParticles () { 58 59 // Updated 60 for (var i = 0; i < particles.length; i++) { 61 particles[i].update(); 62 } 63 64 // Remove dead particles 65 for (var i = particles.length - 1; i >= 0; i--) { 66 if (particles[i].lifeSpan < 0) { 67 particles[i].die(); 68 particles.splice(i, 1); 69 } 70 } 71 72 } 73 74 function loop () { 75 requestAnimationFrame(loop); 76 updateParticles(); 77 } 78 79 /** 80 * Particles 81 */ 82 83 function Particle () { 84 85 this.character = "*"; 86 this.lifeSpan = 120; //ms 87 this.initialStyles = { 88 "position": "fixed", 89 "top": "0", //å¿ é¡»å 90 "display": "block", 91 "pointerEvents": "none", 92 "z-index": "10000000", 93 "fontSize": "20px", 94 "will-change": "transform" 95 }; 96 97 // Init, and set properties 98 this.init = function (x, y, color) { 99 100 this.velocity = { 101 x: (Math.random() < 0.5 ? -1 : 1) * (Math.random() / 2), 102 y: 1 103 }; 104 105 this.position = { x: x - 10, y: y - 20 }; 106 this.initialStyles.color = color; 107 // console.log(color); 108 109 this.element = document.createElement('span'); 110 this.element.innerHTML = this.character; 111 applyProperties(this.element, this.initialStyles); 112 this.update(); 113 114 document.body.appendChild(this.element); 115 }; 116 117 this.update = function () { 118 this.position.x += this.velocity.x; 119 this.position.y += this.velocity.y; 120 this.lifeSpan--; 121 122 this.element.style.transform = "translate3d(" + this.position.x + "px," + this.position.y + "px,0) scale(" + (this.lifeSpan / 120) + ")"; 123 } 124 125 this.die = function () { 126 this.element.parentNode.removeChild(this.element); 127 } 128 129 } 130 131 /** 132 * Utils 133 */ 134 135 // Applies css `properties` to an element. 136 function applyProperties (target, properties) { 137 for (var key in properties) { 138 target.style[key] = properties[key]; 139 } 140 } 141 142 init(); 143})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.