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
MongoDB Atlas runs apps anywhere Icon
MongoDB Atlas runs apps anywhere

Deploy in 115+ regions with the modern database for every enterprise.

MongoDB Atlas gives you the freedom to build and run modern applications anywhere—across AWS, Azure, and Google Cloud. With global availability in over 115 regions, Atlas lets you deploy close to your users, meet compliance needs, and scale with confidence across any geography.
Start Free
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