48 lines
No EOL
910 B
HTML
48 lines
No EOL
910 B
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<link rel="stylesheet" href="style.css">
|
|
<script src="https://js.cx/libs/animate.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
<div id="path">
|
|
<div id="brick"></div>
|
|
</div>
|
|
|
|
<script>
|
|
function makeEaseOut(timing) {
|
|
return function(timeFraction) {
|
|
return 1 - timing(1 - timeFraction);
|
|
}
|
|
}
|
|
|
|
function bounce(timeFraction) {
|
|
for (let a = 0, b = 1; 1; a += b, b /= 2) {
|
|
if (timeFraction >= (7 - 4 * a) / 11) {
|
|
return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
let bounceEaseOut = makeEaseOut(bounce);
|
|
|
|
brick.onclick = function() {
|
|
animate({
|
|
duration: 3000,
|
|
timing: bounceEaseOut,
|
|
draw: function(progress) {
|
|
brick.style.left = progress * 500 + 'px';
|
|
}
|
|
});
|
|
};
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
</html> |