Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created September 30, 2018 16:14
Show Gist options
  • Save zerobias/a06130e79f197d5e50238b1c79e1bc6e to your computer and use it in GitHub Desktop.
Save zerobias/a06130e79f197d5e50238b1c79e1bc6e to your computer and use it in GitHub Desktop.
Transition cursor ball https://now-iqntlcnjeu.now.sh
p{padding-left:60px;}
#foo{
border-radius:50px;
width:50px;
height:50px;
background:#c00;
position:absolute;
top:0;
left:0;
transition: transform 1s;
}
<!DOCTYPE html>
<html>
<head>
<title>transition cursor ball</title>
<link href="/cursorball.css" rel="stylesheet">
</head>
<body>
<p>Click anywhere to move the ball</p>
<div id="foo"></div>
<script src="/cursorball.js"></script>
</body>
</html>
const f = document.getElementById('foo');
document.addEventListener('click', function(ev){
f.style.transform = 'translateY('+(ev.clientY-25)+'px)';
f.style.transform += 'translateX('+(ev.clientX-25)+'px)';
},false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment