Skip to content

Instantly share code, notes, and snippets.

@hiikezoe
Created July 21, 2022 21:41
Show Gist options
  • Save hiikezoe/cd56f65c43c788c838a623ed868b39d5 to your computer and use it in GitHub Desktop.
Save hiikezoe/cd56f65c43c788c838a623ed868b39d5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<style>
html, body {
margin: 0;
padding: 0;
}
@keyframes anim {
from { transform: translateX(0vh); }
to { transform: translateX(-100vw); }
}
#target {
transform-origin: 100vw 50vh;
width: 100px;
height: 100px;
border: 10px green solid;
background: linear-gradient(90deg, #B2A2CD 25%, #5F5370 25%, #5F5370 50%, #D2A2BD 50%, #D2A2BD 75%, #000000 75%, #000000 100%);
background-repeat: repeat;
}
</style>
<div id="target"></div>
<script>
window.onload = () => {
target.style.animation = "anim 10s linear";
target.addEventListener("animationstart", () => {
window.requestAnimationFrame(() => {
console.log("In rAF: " + document.timeline.currentTime + "\n");
});
console.log(document.timeline.currentTime + "\n");
var valueAtStart = document.timeline.currentTime;
var timeAtStart = window.performance.now();
while (window.performance.now() - timeAtStart < 100) {
// Wait 100ms
}
});
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment