Skip to content

Instantly share code, notes, and snippets.

@theanhdo94
Last active January 21, 2017 03:26
Show Gist options
  • Select an option

  • Save theanhdo94/384d91ac211ae2fe1d53d5a8c8355d4d to your computer and use it in GitHub Desktop.

Select an option

Save theanhdo94/384d91ac211ae2fe1d53d5a8c8355d4d to your computer and use it in GitHub Desktop.
Custom style for cursor on web UX
<!-- HTML -->
<div id="follower">
<div id="circle1"></div>
<div id="circle2"></div>
</div>
<!-- CSS -->
#follower {
position: absolute;
top: 50%;
left: 50%;
}
#follower #circle1 {
position: absolute;
-webkit-animation: pulse 2s infinite; /* Chrome, Safari, Opera */
animation: pulse 2s infinite;
background: #fff;
border-radius: 50%;
height: 0em;
width: 0em;
margin-top: 0em;
margin-left: 0em;
}
#follower #circle2 {
position: absolute;
-webkit-animation: pulse 4s infinite; /* Chrome, Safari, Opera */
animation: pulse 4s infinite;
background: rgba(200,0,0,0.8);
border-radius: 50%;
height: 0em;
width: 0em;
margin-top: 0em;
margin-left: 0em;
}
@-moz-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@-webkit-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@-o-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
<!-- Javascripts -->
(function () {
var follower, init, mouseX, mouseY, positionElement, printout, timer;
follower = document.getElementById('follower');
printout = document.getElementById('printout');
mouseX = function (_this) {
return function (event) {
return event.clientX;
};
}(this);
mouseY = function (_this) {
return function (event) {
return event.clientY;
};
}(this);
positionElement = function (_this) {
return function (event) {
var mouse;
mouse = {
x: mouseX(event),
y: mouseY(event)
};
follower.style.top = mouse.y + 'px';
return follower.style.left = mouse.x + 'px';
};
}(this);
timer = false;
window.onmousemove = init = function (_this) {
return function (event) {
var _event;
_event = event;
return timer = setTimeout(function () {
return positionElement(_event);
}, 1);
};
}(this);
}.call(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment