npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

toggle-transition

v2.0.0

Published

Tiny vanilla JavaScript plugin enables you to show/hide/toggle DOM Element taking advantage of CSS transitions and without worrying about details.

Downloads

31

Readme

toggleTransition.js

Tiny vanilla JavaScript plugin that enables you to show/hide/toggle DOM Element taking advantage of CSS transitions and without worrying about details.

npm npm bundle size (version) NPM npm

Problem

CSS3 transition doesn't work with display property.

CSS3 transitions don't apply to the display property, i.e., you can't do any sort of transition from display: none to display: block (or any combination).

Transitions on the CSS display property on StackOverflow.

How it solves the problem

The plugin shows/hides an element with CSS3 transition effects and manages its display property behind the scenes.

In case of hidding the element, toggleTransition.js sets element's display property to none right after transition ends, making use of onTransitionEnd event.

If case of showing the element, it sets the display back to initial state. Then CSS transition runs and the element appears smoothly.

In Action

toggle transition in action

Quickstart

Use CDN

<script src="https://unpkg.com/toggle-transition@latest/toggleTransition.min.js"></script>

Codepen

<style>
  body {
    background-color: whitesmoke;
  }

  .example {
    width: 300px;
    background-color: floralwhite;
    padding: 10px 20px;
    box-shadow: 3px 3px 19px rgba(0, 0, 0, 0.2);
    position: relative;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    transform: translateY(0px) scale(0.9);
  }

  .is_shown {
    opacity: 1;
    transform: translateY(10px) scale(1);
  }

  .is_hidden {
    opacity: 0;
    transform: translateY(0) scale(0.9);
  }
</style>

<button class="button">Toggle It!</button>

<div class="example is_hidden">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa quisquam laboriosam quos tempore nobis quam officiis commodi. Eaque dolor eius animi voluptatum inventore? Eveniet, perspiciatis itaque obcaecati explicabo fugit blanditiis!
</div>

<script>
  var instance = new ToggleTransition(document.querySelector('.example'), {
    showTransitionClassname: "is_shown",
    hideTransitionClassname: "is_hidden",
    manageVisibilityWith: "visibility", // or "display"
    onShowTransitionEnd: function (e, x) {
      console.log("after show transition callback", e, x);
    },
    onHideTransitionEnd: function (e, x) {
      console.log("after hide transition callback", e, x);
    },
  });

  document.querySelector(".button").addEventListener("click", function () {
    instance.toggle();
  });
</script>

Examples

Install

Add package with your favorite package manager:

# npm
npm install toggle-transition

# yarn
yarn add toggle-transition

Add it to your project:

require "toggle-transition"

Contribute

All of these will be appreciated:

  • Blog or tweet about the project
  • Improve documentation
  • Fix a bug
  • Implement a new feature
  • Discuss potential ways to improve project
  • Add a TODO to the code
  • Improve existing implementation, performance, etc.

This list of TODOs.md has been kindly created for your convenience.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

License

The code licensed under the MIT License. The logo and the sign used in the header are under Creative Commons Attribution 3.0 Unported License. You are free to do whatever you want, don't remove my name from the source.

Do you like this?

"Buy Me A Coffee"