All Projects → cferdinandi → Drop

cferdinandi / Drop

Licence: mit
A small CSS component that turns browser-native <details> elements into dropdown menus.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Drop

Cpp redis
C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform - NO LONGER MAINTAINED - Please check https://github.com/cpp-redis/cpp_redis
Stars: ✭ 855 (+1139.13%)
Mutual labels:  no-dependencies
Livecoding.tw
官網
Stars: ✭ 42 (-39.13%)
Mutual labels:  html-css
Notes Summary
知识梳理、总结,写博客的地方。欢迎star
Stars: ✭ 58 (-15.94%)
Mutual labels:  html-css
Vanilla Emoji Picker
Modern emoji picker. Super light 2kb gzipped, simple and no frameworks 😻
Stars: ✭ 20 (-71.01%)
Mutual labels:  no-dependencies
Curriculum
Overview of the different modules and learning goals of the program.
Stars: ✭ 40 (-42.03%)
Mutual labels:  html-css
Nonstd Lite
Parent of *-lite repositories, a migration path to post-C++11 features for pre-C++11 environments
Stars: ✭ 46 (-33.33%)
Mutual labels:  no-dependencies
Hed
vim like hex editor
Stars: ✭ 23 (-66.67%)
Mutual labels:  no-dependencies
Physunits Ct Cpp11
A small C++11, C++14 header-only library for compile-time dimensional analysis and unit/quantity manipulation and conversion
Stars: ✭ 67 (-2.9%)
Mutual labels:  no-dependencies
X Ray
X-Ray is a script that lets users toggle password visibility in forms.
Stars: ✭ 40 (-42.03%)
Mutual labels:  no-dependencies
Expected Dark
Expected objects for C++11 and later (and later perhaps C++98 )
Stars: ✭ 55 (-20.29%)
Mutual labels:  no-dependencies
Mf Blogstarter
Eleventy + Tailwind CSS blog starter by Marc Filleul
Stars: ✭ 21 (-69.57%)
Mutual labels:  html-css
Observer Ptr Lite
observer-ptr - An observer_ptr for C++98 and later in a single-file header-only library (Extensions for Library Fundamentals, v2, v3)
Stars: ✭ 34 (-50.72%)
Mutual labels:  no-dependencies
Front End Developer Questions
前端开发面试题,已基本更新完毕。(后续会补充)
Stars: ✭ 49 (-28.99%)
Mutual labels:  html-css
Humblelogging
HumbleLogging is a lightweight C++ logging framework. It aims to be extendible, easy to understand and as fast as possible.
Stars: ✭ 15 (-78.26%)
Mutual labels:  no-dependencies
Alagarr
🦍 Alagarr is a request-response helper library that removes the boilerplate from your Node.js (AWS Lambda) serverless functions and helps make your code portable.
Stars: ✭ 58 (-15.94%)
Mutual labels:  no-dependencies
Metro Ui Css
Impressive component library for expressive web development! Build responsive projects on the web with the first front-end component library in Metro Style. And now there are even more opportunities every day!
Stars: ✭ 6,843 (+9817.39%)
Mutual labels:  no-dependencies
Nameof
Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum
Stars: ✭ 1,017 (+1373.91%)
Mutual labels:  no-dependencies
Printf
Tiny, fast, non-dependent and fully loaded printf implementation for embedded systems. Extensive test suite passing.
Stars: ✭ 1,157 (+1576.81%)
Mutual labels:  no-dependencies
Pure Css3 Animated Border
Pure CSS3 animated border for all html element.
Stars: ✭ 63 (-8.7%)
Mutual labels:  html-css
Flutter html
A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
Stars: ✭ 1,046 (+1415.94%)
Mutual labels:  html-css

Drop Build Status

A small CSS component that turns browser-native <details> elements into dropdown menus.

View the demo on CodePen →

Getting Started | Dropdown Groups | Customizing | What's new? | Browser Compatibility | License


Interested in doing more with browser-native methods and APIs? Check out my Vanilla JS Pocket Guides or join the Vanilla JS Academy and level-up as a web developer. 🚀


Getting Started

Compiled and production-ready code can be found in the dist directory. The src directory contains development code.

1. Include Drop on your site.

In addition to a small CSS file, you should include a <details> element polyfill to add support to IE and Edge.

Direct Download

You can download the files directly from GitHub.

<link rel="stylesheet" type="text/css" href="path/to/drop.min.css">
<script src="path/to/details-element-polyfill.js"></script>

CDN

You can also use the jsDelivr CDN. I recommend linking to a specific version number or version range to prevent major updates from breaking your site. Smooth Scroll uses semantic versioning.

<!-- Always get the latest version -->
<!-- Not recommended for production sites! -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/drop/dist/drop.min.css">

<!-- Get minor updates and patch fixes within a major version -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/drop.min.css">

<!-- Get patch fixes within a minor version -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/drop.min.css">

<!-- Get a specific version -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/drop.min.css">

And here's a CDN for the polyfill.

NPM

You can also use NPM (or your favorite package manager).

npm install dropjs

2. Add the markup to your HTML.

Create a standard <details> element, and add the .dropdown class. It can stand on its own, or be wrapped in a list item (<li>) as part of a bigger navigation menu.

The text inside the <summary> element is what toggles the dropdown. Add an unordered list (<ul>) with your dropdown items.

<details class="dropdown">
	<summary>This has dropdown items</summary>
	<ul>
		<li><a href="#hi">Hi</a></li>
		<li><a href="#universe">Universe</a></li>
	</ul>
</details>

If the dropdown is in a navigation and will appear close to the right side of the viewport where it's content might get clipped, add the dropdown-right class to shift it's positioning.

<details class="dropdown dropdown-right">
	<summary>This has dropdown items, too</summary>
	<ul>
		<li><a href="#hermoine">Hermione</a></li>
		<li><a href="#harry">Harry Potter</a></li>
	</ul>
</details>

And that's it, you're done. Nice work!

Explore a demo on CodePen →

Dropdown Groups

By default, the behavior of one dropdown menu does not affect the other.

If you want all other dropdown menus in a group to close when one is opened, add the included drop.js script.

<!-- Direct Download -->
<script src="path/to/drop.min.js"></script>

<!-- CDN -->
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/js/drop.min.js"></script>

Then, instantiate it by passing in the parent element for your dropdown group (or a selector). If you changed the class for your dropdown menus, pass that in as a second argument.

var dropdownGroup = new Drop('#my-nav');

// Using a different class
var otherDropdownGroup = new Drop('#another-nav', '.dropdown-alt');

Explore dropdown groups on CodePen →

Canceling a dropdown group

You can cancel this functionality with the destroy() method.

dropdownGroup.destroy();

Customizing

Drop includes very minimal styling. You're encouraged to add your own styles to match your theme and layout, including changing the color of the text and dropdown menu links.

What's new?

Drop 12 completely ditches the old JavaScript plugin and markup in favor of the browser-native <details> element. You'll need to recreate your markup using the new pattern.

Browser Compatibility

Drop has the same support as the <details> element. That means that it works in all modern browsers, but not IE or Edge. In unsupported, the content will always be expanded.

Polyfill

You can add Edge and IE support with the lightweight <details> element polyfill. Once Edge migrates to Blink, it will support the element natively.

License

The code is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].