Skip to content

Commit cc80010

Browse files
committed
emojiCursor
1 parent 9ee18bb commit cc80010

2 files changed

Lines changed: 124 additions & 1 deletion

File tree

js/emojiCursor.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*!
2+
* Emoji Cursor.js
3+
* -- 90's cursors collection
4+
* -- http://tholman.com/90s-cursors
5+
*/
6+
7+
(function emojiCursor() {
8+
9+
var possibleEmoji = ["😀", "😂", "😆", "😊"];
10+
var width = window.innerWidth;
11+
var height = window.innerHeight;
12+
var cursor = {x: width/2, y: width/2};
13+
var particles = [];
14+
15+
function init() {
16+
bindEvents();
17+
loop();
18+
}
19+
20+
// Bind events that are needed
21+
function bindEvents() {
22+
document.addEventListener('mousemove', onMouseMove);
23+
window.addEventListener('resize', onWindowResize);
24+
}
25+
26+
function onWindowResize(e) {
27+
width = window.innerWidth;
28+
height = window.innerHeight;
29+
}
30+
31+
function onMouseMove(e) {
32+
cursor.x = e.clientX;
33+
cursor.y = e.clientY;
34+
addParticle( cursor.x, cursor.y, possibleEmoji[Math.floor(Math.random()*possibleEmoji.length)]);
35+
}
36+
37+
function addParticle(x, y, character) {
38+
var particle = new Particle();
39+
particle.init(x, y, character);
40+
particles.push(particle);
41+
}
42+
43+
function updateParticles() {
44+
45+
// Updated
46+
for( var i = 0; i < particles.length; i++ ) {
47+
particles[i].update();
48+
}
49+
50+
// Remove dead particles
51+
for( var i = particles.length -1; i >= 0; i-- ) {
52+
if( particles[i].lifeSpan < 0 ) {
53+
particles[i].die();
54+
particles.splice(i, 1);
55+
}
56+
}
57+
58+
}
59+
60+
function loop() {
61+
requestAnimationFrame(loop);
62+
updateParticles();
63+
}
64+
65+
/**
66+
* Particles
67+
*/
68+
69+
function Particle() {
70+
71+
this.lifeSpan = 120; //ms
72+
this.initialStyles ={
73+
"position": "absolute",
74+
"display": "block",
75+
"pointerEvents": "none",
76+
"z-index": "10000000",
77+
"fontSize": "16px"
78+
};
79+
80+
// Init, and set properties
81+
this.init = function(x, y, character) {
82+
83+
this.velocity = {
84+
x: (Math.random() < 0.5 ? -1 : 1) * (Math.random() / 2),
85+
y: 1
86+
};
87+
88+
this.position = {x: x - 10, y: y - 20};
89+
90+
this.element = document.createElement('span');
91+
this.element.innerHTML = character;
92+
applyProperties(this.element, this.initialStyles);
93+
this.update();
94+
95+
document.body.appendChild(this.element);
96+
};
97+
98+
this.update = function() {
99+
this.position.x += this.velocity.x;
100+
this.position.y += this.velocity.y;
101+
this.lifeSpan--;
102+
103+
this.element.style.transform = "translate3d(" + this.position.x + "px," + this.position.y + "px,0) scale(" + (this.lifeSpan / 120) + ")";
104+
}
105+
106+
this.die = function() {
107+
this.element.parentNode.removeChild(this.element);
108+
}
109+
110+
}
111+
112+
/**
113+
* Utils
114+
*/
115+
116+
// Applies css `properties` to an element.
117+
function applyProperties( target, properties ) {
118+
for( var key in properties ) {
119+
target.style[ key ] = properties[ key ];
120+
}
121+
}
122+
123+
init();
124+
})();

js/fairyDustCursor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787

8888
this.position = {x: x - 10, y: y - 20};
8989
this.initialStyles.color = color;
90-
console.log(color);
9190

9291
this.element = document.createElement('span');
9392
this.element.innerHTML = this.character;

0 commit comments

Comments
 (0)