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

Overview

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.

Comments
  • Collapsed content is still visible to screen readers

    Collapsed content is still visible to screen readers

    Hello! 👋

    We're using dom-slider in @sparkdesignsystem and we're running into an accessibility issue. Because dom-slider does not use display: none when hiding the content, the content is still available to screen readers when it should be hidden. This is only the case after the contents are hidden by dom-slider; you may need to expand and then collapse a component to see this issue in action.

    Steps to Reproduce using VoiceOver on macOS

    1. Open example.html in a browser
    2. Turn on VoiceOver (Cmd+F5, by default)
    3. Refresh example.html to put VoiceOver focus in the page.
    4. Use the VoiceOver navigation (Ctrl+Option+Arrows, by default) to scroll around the page. Note that the collapsed contents are not read by the screen reader.
    5. Expand and Collapse a toggle using the VoiceOver trigger (Ctrl+Option+Space, by default)
    6. Scroll around with VO navigation again and observe that the contents are still visible to screen readers even when hidden.
    bug enhancement 
    opened by bobwise 6
  • Cannot redefine property: slideDown

    Cannot redefine property: slideDown

    Hi, I created a little script which uses "dom-slider" and working well "alone", but when I put on production website where there are many other scripts, including jQuery, I got this error: Cannot redefine property: slideDown.

    I research quickly and saw something related with "slideDown" (re)declaration (source).

    I don't know it's a problem on my side, and there is a way to avoid this conflict, like the "dom-slider" method should work only my application scope. Or if you could fix it following the idea on define configurable: true but we need to think on the "side-effects" from this change.

    Let me know you think about this, please.

    Thanks in advance

    PS: there is a question and some comments, maybe could help us :)

    bug 
    opened by jonaswebdev 2
  • Doesn't work if element is hidden by default via CSS

    Doesn't work if element is hidden by default via CSS

    I was looking for something like this (thanks for writing it), but it doesn't look like it works if the element to be toggled is hidden by default using display: none

    For instance, if this were to be used for a FAQ toggler, the answers wouldn't be revealed when the questions were clicked.

    opened by bridgeport 2
  • How to reinit height?

    How to reinit height?

    If ill use slideDown, and after inside element change height (like add some items in spoiler), after slideUp and slideDOwn will bug, because start animation from old height.

    opened by Venegrad 1
  • feat(scripts): add prepublish script and .npmignore

    feat(scripts): add prepublish script and .npmignore

    Hi,

    Thank you for merging my previous PR. I noticed that the dist/dom-slider.js was out of date with respect to the /src. I added a build step to prevent this in the future, I also added an .npmignore

    I hope you like it!

    opened by eenewbsauce 1
  • Do not extend Object prototype

    Do not extend Object prototype

    Why not just export the functions, like a normal library? Extending Object prototype is way too invasive, and especially in the way it is done here, it will affect every single for (let x in y) loop in the entire script, causing them to iterate over your functions.

    opened by d07RiV 1
  • Merge pull request #11 from BrentonCozby/dependabot/npm_and_yarn/lodash-4.17.15

    Merge pull request #11 from BrentonCozby/dependabot/npm_and_yarn/lodash-4.17.15

    Bumps lodash from 4.17.11 to 4.17.15.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump path-parse from 1.0.6 to 1.0.7

    Bump path-parse from 1.0.6 to 1.0.7

    Bumps path-parse from 1.0.6 to 1.0.7.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • padding-top and padding-bottom is wrongly calculated

    padding-top and padding-bottom is wrongly calculated

    padding-top and padding-bottom is wrongly calculated when element is closed by default with display: none or DOM-slider-hidden

    on the first opening the padding-top and padding-bottom is always 0px

    opened by lubomirblazekcz 4
Releases(2.2.0)
  • 2.2.0(Apr 25, 2021)

  • 2.1.4(Apr 18, 2020)

    When using slideUp, sometimes the animation will jump instead of sliding up smoothly. I'm not sure why adding a delay seems to fix this, but this will be the solution until a better one is found.

    A 20ms minimum delay is now standard for all dom-slider "slide" methods.

    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Mar 25, 2020)

    Removed dom-slider methods from the Object prototype chain; now they are independent modules. As a result, you must now provide the element as an argument: instead of being able to do element.slideDown(), you must do slideDown({element}). Also, I added aria-hidden to prevent screen readers from reading hidden elements.

    Source code(tar.gz)
    Source code(zip)
Owner
Brenton Cozby
Brenton Cozby
RSS feeds for the masses. Create feeds for sites which have none.

RSS Manufaktur A template to build RSS Feeds. In short, RSS Manufaktur takes information of a blog and transforms it into a custom RSS feed for your e

Cyber Design Inframanufaktur 13 Oct 20, 2022
A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Basic2Lisp A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp. Syntax Print-Sth Put some-value to standard output. PRI

Hana Yabuki 5 Jul 10, 2022
Uncensorable, immutable microblogging platform that is completely decentralized and does not rely on any centralized systems.

Zooko Truly decentralized, immutable and uncensorable microblogging Zooko is a working-example, proof-of-concept proving that you can have a decentral

Publius Federalist 152 Apr 20, 2022
Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

Hacktoberfest Indonesia Apa Itu Hacktoberfest ? Hacktoberfest adalah acara tahunan yang bertujuan untuk mendorong berkontribusi kedalam ekosistem open

Juan Daniel 5 Dec 15, 2022
this is a single-page web application. we built a book website where the user can add , remove and display books. we used modules to implement these functionalities. also, we used the Date class to display the date and time.

Awsome Books In this Project, we have built A Books websites. Built With ?? HTML CSS javascript Git & Github Live Demo Here you can find the live Demo

Nedjwa Bouraiou 10 Aug 3, 2022
A public board for all the Computer Society and Students to display their profile. An online year-book for you to display your profile in the most creative manner

Student's Yearbook by IEEE Computer Society Student's yearbook is an open-source project which intends to dispaly the students who will be graduating

IEEE Computer Society 11 Dec 18, 2022
A quick and easy to use security reconnaissance webapp tool, does OSINT, analysis and red-teaming in both passive and active mode. Written in nodeJS and Electron.

ᵔᴥᵔ RedJoust A quick and easy to use security reconnaissance webapp tool, does OSINT, analysis and red-teaming in both passive and active mode. Writte

Dave 17 Oct 31, 2022
An interactive Bitcoin tutorial for orange-pilled beginners. Illustrates technical Bitcoin concepts using JavaScript and some Bitcoin Core RPC commands. Programming experience is helpful, but not required.

Try Bitcoin Try Bitcoin is an interactive Bitcoin tutorial inspired by and forked from Try Regex, which is inspired by Try Ruby and Try Haskell. It il

Stacie Waleyko 33 Nov 25, 2022
Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

null 7 Jan 14, 2022
🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

?? TypeScript Primitives type TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types

CodelyTV 82 Dec 7, 2022
A Browser extension that not only makes your browsing experience safe but makes it optimized

Sia Sia is a browser extension that not only makes your browsing experience safe but makes it optimized Table of Contents About The Project Built With

Arun Govind M 14 Feb 23, 2022
It's not butter, but it's root.

margerine Episode 2: Revenge of the ¯\_(ツ)_/¯ margerine is a root exploit and adb enabler for the DJI Air Unit (wm150), Caddx Vista (lt150), FPV Goggl

fpv.wtf 183 Dec 24, 2022
WhyProfiler is a CPU profiler for Jupyter notebook that not only identifies hotspots but can suggest faster alternatives.

Introduction WhyProfiler is a CPU profiler for Jupyter notebook that not only identifies hotspots but can suggest faster alternatives. It is powered b

Robusta 44 Dec 5, 2022
🪐 The IPFS gateway for NFT.Storage is not "another gateway", but a caching layer for NFTs that sits on top of existing IPFS public gateways.

nftstorage.link The IPFS gateway for nft.storage is not "another gateway", but a caching layer for NFT’s that sits on top of existing IPFS public gate

NFT.Storage 37 Dec 19, 2022
our features are few but we provide the best and it is not uncommon to find in other npmjs

hikki-me our features are few but we provide the best and it is not uncommon to find in other npmjs Installation Install hikki-me with npm npm install

(Anto) 10 Jul 10, 2022
BttrLazyLoading is a Jquery plugin that allows your web application to defer image loading until images are scrolled to but not only

BttrLazyLoading.js BttrLazyLoading is a Jquery plugin that allows your web application to defer image loading until images are scrolled to but not onl

Julien Renaux 410 Dec 14, 2022
A dad joke is a short joke, typically a pun, presented as a one-liner or a question and answer, but not a narrative

A dad joke is a short joke, typically a pun, presented as a one-liner or a question and answer, but not a narrative. Many dad jokes may be considered anti-jokes, deriving humor from an intentionally not funny punchline. daddy-jokes is an npm package that returns a dad joke when implemented.

Abir Bhattacharya 5 Oct 23, 2022