Created
October 8, 2013 08:43
-
-
Save dani-z/6881616 to your computer and use it in GitHub Desktop.
A Pen by dani-z.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="menu"> | |
<a class="js-toggle-menu" href="#">Open / Close</a> | |
<ul> | |
<li>Item 1</li> | |
<li>Item 2</li> | |
<li>Item 3</li> | |
<li>Item 4</li> | |
</ul> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.js-toggle-menu').on('click', function( evt ) { | |
evt.preventDefault(); | |
var target = $('ul'); | |
target.slideToggleH(); | |
}); | |
// TODO: Improvements using custom options and grab the width/height automatic | |
(function($) { | |
var defaults = { | |
speed: 0 | |
} | |
$.fn.extend({ | |
slideRight: function() { | |
return this.each(function() { | |
$(this).animate({ | |
left: '0' | |
}, 200); | |
}); | |
}, | |
slideLeft: function() { | |
return this.each(function() { | |
$(this).animate({ | |
left: '-270px' | |
}, 200); | |
}); | |
}, | |
slideToggleH: function() { | |
return this.each(function() { | |
var el = $(this); | |
if (el.css('left') == '-270px') { | |
el.slideRight(); | |
} else { | |
el.slideLeft(); | |
} | |
}); | |
} | |
}); | |
})(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.menu { | |
position: relative; | |
} | |
ul { | |
position: absolute; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment