Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(math): lerp and remap utils #31

Merged
merged 1 commit into from
May 31, 2023
Merged

feat(math): lerp and remap utils #31

merged 1 commit into from
May 31, 2023

Conversation

osalinasv
Copy link
Contributor

Description

Add lerp and remap utils which are commonly used for animation, i.e:

// Smoothly animate an HTML element's x position based on how far the user has scrolled
function moveElementOnScroll(event) {
  // ...
  const progress = getScrollProgress(event)
  animatedElement.style.setProperty('--x', lerp(100, 300, progress))
})
// Update the camera position of a WebGL context based on the window's width
function zoomCameraOnResize(event) {
  camera.position.z = remap(window.innerWidth, 360, 1920, 10, 50)
}

@antfu antfu merged commit f8b244d into antfu:main May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants