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
Auth0 for AI Agents now in GA Icon
Auth0 for AI Agents now in GA

Ready to implement AI with confidence (without sacrificing security)?

Connect your AI agents to apps and data more securely, give users control over the actions AI agents can perform and the data they can access, and enable human confirmation for critical agent actions.
Start building today
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