Using JavaScript to animate an element open and closed hasn't traditionally been a straightforward task, especially if it contains dynamically sized content. You could go with something like jQuery's slideToggle(), but that path would require you to take on a lot more code than necessary. Another option is using CSS to change the max-height value of an element, but this approach is filled with arbitrariness and difficult to pull off well when you're not sure how much content you'll be animating over. This library gets the job done using the Web Animations API, and it doesn't require elements to have fixed heights. Instead, element heights are calculated based on their contents, and then the appropriate values are applied to trigger a smooth, native transition. The animations themselves are powered by the same mechanics used within CSS transitions, making it one of the best ways to pull it off in terms of performance.

Features

  • Make sure your target element is set to display: none
  • Run npm install slide-element, or use a CDN like unpkg
  • It's small, smooth, and focuses on doing one job well: sliding stuff open and closed
  • Slide Elements Down
  • Slide Elements Up
  • Interrupt In-Progress Animations

Project Samples

Project Activity

See All Activity >

Categories

Libraries

License

ISC License

Follow slide-element

slide-element Web Site

Other Useful Business Software
Our Free Plans just got better! | Auth0 Icon
Our Free Plans just got better! | Auth0

With up to 25k MAUs and unlimited Okta connections, our Free Plan lets you focus on what you do best—building great apps.

You asked, we delivered! Auth0 is excited to expand our Free and Paid plans to include more options so you can focus on building, deploying, and scaling applications without having to worry about your security. Auth0 now, thank yourself later.
Try free now
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of slide-element!

Additional Project Details

Programming Language

TypeScript

Related Categories

TypeScript Libraries

Registered

2023-10-03