toggle-on-click-jquery
v1.0.2
Published
Show something on an element click and hide on any second outside click
Downloads
2
Maintainers
Readme
toggle-on-click-jquery
- Opens by
- Click
- Closes by
- Second click
- Mousedown outside
- Esc
Demo
https://webdeveloper.pro/demo/toggle-on-click-jquery/demo.html
Install
npm install toggle-on-click-jquery --save
Setup
import toggleOnClick from 'toggle-on-click-jquery';
Usage
<p><button id="js-button">Click here</button></p>
<div class="menu" id="js-menu">
Menu or something else...
</div>
$(document).ready(function () {
toggleOnClick(
$('#js-button'), // Button
$('#js-menu'), // Target
{
// How to open (optional)
open($element) {
$element.slideDown(200);
},
// How to close (optional)
close($element) {
$element.slideUp(200);
}
}
);
})
Close menu by trigger:
$('#js-menu').trigger('toggleOnClickClose');
License
MIT