Code Monkey home page Code Monkey logo

toggleable's Introduction

toggleable

jQuery plugin that hide/shows content - accordion menu style, but not quite like that.

Markup

Here is what the markup should look like (tags are to your convenience, only classes matter) :

<ul>
	<li class="ux-toggleable">
		<div class="ux-toggle-switch">
			Show/Hide me
		</div>
		<ul class="ux-toggle">
			<li>
				<a href="#">
					Link 1
				</a>
			</li>
			<li>
				<a href="#">
					Link 2
				</a>
			</li>
			<li>
				<a href="#">
					Link 3
				</a>
			</li>
		</ul>
	</li>
</ul>

Initilization :

$(function(){
	$('.ux-toggleable').toggleable();
});

Now whenever the user clicks "Show/Hide me", the subsequent

    is toggled. Additionally, elements that are hidden by the plugin get a "closed" class (in this case the li.ux-toggleable.

    Options

    You can change the class name that closed toggles get like this :

    $(function(){
    	$('.ux-toggleable').toggleable({closedClass: 'my-closed-class'});
    });

    By default, the toggleable plugin will close all toggles. You can prevent this by passing an option at initialization time :

    $(function(){
    	$('.ux-toggleable').toggleable({autoclose: false});
    });

    Alternatively, you can also specify in the markup that you want only some toggles to be kept open by setting an data-open property on the toggle.

    <ul>
    	<li class="ux-toggleable" data-open>
    		<div class="ux-toggle-switch">
    			Show/Hide me
    		</div>
    		<ul class="ux-toggle">
    			<li>
    				<a href="#">
    					Link 1
    				</a>
    			</li>
    			<li>
    				<a href="#">
    					Link 2
    				</a>
    			</li>
    			<li>
    				<a href="#">
    					Link 3
    				</a>
    			</li>
    		</ul>
    	</li>
    </ul>

toggleable's People

Contributors

ls-yannick avatar

Stargazers

Thomas Gimesi avatar

Watchers

James Cloos avatar  avatar

toggleable's Issues

Listen for more than click events

Since this kind of menus are handy for mobile devices, it makes sense to listen to touch events, or at least make it a configurable option.

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.