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

native-slide-toggle

v1.1.3

Published

VanillaJS slide toggle

Downloads

13

Readme

native slide toggle

Vanilla JS mobile friendly version of jQuery.slideToggle

about

slide toggle to open or close content using CSS transition and transitionend event.

demo

demo

  • native slide toggle vs jQuery.slideToggle http://codepen.io/kunukn/full/yaYvrp/

browser support

| | | | | | | |:---:|:---:|:---:|:---:|:---:|:---:| | 50+ ✅ | 40+ ✅ | 9+ ✅ | 40+ ✅ | 12+ ✅ | 11+ ✅ |

features

  • Small library - JS is ~3kb minified and CSS is ~900 bytes minified
  • CSS max-height transition on dynamically calculated height value
  • Simple html structure with minimum CSS class usage
  • Max-height is dynamically set and reset after the animation
  • Tabbing is supported
  • Vanilla JS, no other dependency

usage

Check the index.html for inspiration.

  • Add reference to nst.min.js and nst.min.css in the html page
  • Apply the markup structure
  • Apply custom css to override the library css

html structure

Basic example

 <div class="nst-component">
    <button class="nst-toggle">toggle</button>
    <div class="nst-content">
      <div>
        Your content here
      </div>
    </div>
  </div>

nst-component must be a parent element to the nst-content element and the nst-toggle element. The extra div inside the nst-content is for padding and to make the open/close animation look similar to jQuery.slideToggle.

configuration

If you want to start with collapsed state add nst-is-collapsed class to the component. e.g.

 <div class="nst-component nst-is-collapsed">
    <button class="nst-toggle">toggle</button>
    <div class="nst-content">
      <div>
        Your content here
      </div>
    </div>
  </div>

If you want to manually init the component then add the nst-manual-init class to the component. e.g.

 <div class="nst-component nst-manual-init" id="i-want-to-manually-init-this">
    <button class="nst-toggle">toggle</button>
    <div class="nst-content">
      <div>
        Your content here
      </div>
    </div>
  </div>
var myComponentElement = document.getElementById('i-want-to-manually-init-this');
nst.init(myComponentElement);

how does it work?

This uses CSS transition on max-height value. The max-height is dynamically set and removed with JS during expanding and collapsing. The height value is calculated dynamically based on the content. You can rotate the device or resize the browser window where the height is dynamically adjusted.

development

  • Git clone the project or download it
  • npm install
  • npm run start

For minification

  • npm run deploy

supported browsers

Browsers which supports requestAnimationFrame, transitionend event, css max-height transition, document.querySelector and Ecmascript 5.

performance

The max-height triggers layout, paint and composite but is faster than JS animation. https://csstriggers.com/max-height

license

MIT