Giter Site home page Giter Site logo

brentoncozby / dom-slider Goto Github PK

View Code? Open in Web Editor NEW
61.0 6.0 7.0 198 KB

Plain JavaScript version of jQuery's slideToggle(), slideDown(), & slideUp(), but does not use display: none.

License: MIT License

JavaScript 66.23% HTML 27.04% CSS 6.73%
jquery animation vanilla-js accessibility

dom-slider's Introduction

dom-slider

Known Vulnerabilities

It works like jQuery's slideToggle(), slideDown(), & slideUp(), but does not use display: none. Uses CSS3 transitions and element.scrollHeight to animate the height of elements with an unknown height.

dom-fader is a thing too.

Features:

  • Slides elements with a known or unknown height
  • Slides the height, padding, border, and margin (just the top and bottom values).
  • May slide multiple elements at once
  • Returns a Promise resolved with the element
  • Hides elements in a screen-reader-friendly way
  • Zero Dependencies and written in plain JavaScript (compiled to ES5)

Example Usage:

dom-slider CDN link

First, place the dom-slider CDN link in your html file above your own JavaScript files. Hide all the elements that you want to slide down/toggle using display: none in CSS. Then do stuff like below:

const {slideDown, slideUp, slideToggle} = window.domSlider

const box = document.querySelector('.box')

slideToggle({element: box})

slideUp({element: box, slideSpeed: 1200})

slideDown({element: box, slideSpeed: 800, easing: 'easeInOut'})

// Promises (or async/await)
slideDown({element: box, slideSpeed: 500}).then(() => {
  slideUp({element: box, slideSpeed: 300})
})

Options:

The element argument is required, but you may provide the following optional arguments to slideToggle, slideDown, and slideUp:

slideDown({
  element,
  slideSpeed, // speed in milliseconds
  easing, // CSS transition timing function,
  delay, // delay in milliseconds,
  visibleDisplayValue, // the CSS display value when the element is visible; the default value is "block"
})

Print Styling:

dom-slider removes the DOM-slider-hidden CSS class from all elements before printing and adds them back after printing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.