Skip to content

Instantly share code, notes, and snippets.

@busyevolving
Created September 23, 2019 10:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save busyevolving/c98643b1ce5a4221d87a3dcbba9ea3ab to your computer and use it in GitHub Desktop.
Save busyevolving/c98643b1ce5a4221d87a3dcbba9ea3ab to your computer and use it in GitHub Desktop.
Circle Follow Cursor
<span id="circle" class="circle"></span>
jQuery(document).ready(function() {
var mouseX = 0, mouseY = 0;
var xp = 0, yp = 0;
$(document).mousemove(function(e){
mouseX = e.pageX - 30;
mouseY = e.pageY - 30;
});
setInterval(function(){
xp += ((mouseX - xp)/6);
yp += ((mouseY - yp)/6);
$("#circle").css({left: xp +'px', top: yp +'px'});
}, 20);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
@import url(https://fonts.googleapis.com/css?family=Roboto:400,900);
body, html {
position: relative;
height: 100%;
width : 100%;
margin: 0;
background-color: #000000;
}
.circle {
position: absolute;
border: solid 1px #ccc;
width: 60px;
height: 60px;
border-radius: 50%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment