Skip to content

Commit

Permalink
Add support for Velocity.js animations and stop animation queue befor…
Browse files Browse the repository at this point in the history
…e animating.
  • Loading branch information
ComputerWolf committed Sep 18, 2016
1 parent 163e93a commit 3ed9280
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 67 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SlickNav v1.0.7
# SlickNav v1.0.8
## Responsive Mobile Menu jQuery Plugin

[![Join the chat at https://gitter.im/ComputerWolf/SlickNav](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ComputerWolf/SlickNav?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down Expand Up @@ -56,6 +56,7 @@ slicknav.css can be modified to fit website design
'removeIds': true // Remove IDs from all menu elements. Defaults to false if duplicate set to false.
'removeClasses': false // Remove classes from all menu elements.
'brand': '' // Add branding to menu bar.
'animations': 'jquery' // Animation library. Currently supports "jquery" and "velocity".

### Callbacks
'init': function(){}, // Called after SlickNav creation
Expand All @@ -68,7 +69,11 @@ slicknav.css can be modified to fit website design
$('.menu').slicknav('toggle'); // Method to toggle the menu
$('.menu').slicknav('open'); // Method to open the menu
$('.menu').slicknav('close'); // Method to close the menu

### Animations
SlickNav will use jQuery for animations by default. If you wish to use Velocity.js for animating, be sure to include the library in your code before including SlickNav.

### Menu Display
Without any additional configuration, both the original and mobile menus will be displayed. It is recommended to use media queries to hide the original menu and display the mobile menu when appropriate. Modernizr or similar can be used for graceful degradation.

For example:
Expand Down Expand Up @@ -97,4 +102,4 @@ More examples at [SlickNav.com](http://slicknav.com)
* Opera
* IE7+
* Android Browser
* iOS Safari
* iOS Safari
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slicknav",
"version": "1.0.7",
"version": "1.0.8",
"authors": [
"Josh Cope"
],
Expand Down
87 changes: 57 additions & 30 deletions dist/jquery.slicknav.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* SlickNav Responsive Mobile Menu v1.0.7
* SlickNav Responsive Mobile Menu v1.0.8
* (c) 2016 Josh Cope
* licensed under MIT
*/
Expand All @@ -25,6 +25,7 @@
removeClasses: false,
removeStyles: false,
brand: '',
animations: 'jquery',
init: function () {},
beforeOpen: function () {},
beforeClose: function () {},
Expand Down Expand Up @@ -333,23 +334,52 @@
if (animate) {
duration = settings.duration;
}

function afterOpen(trigger, parent) {
$(trigger).removeClass(prefix+'_animating');
$(parent).removeClass(prefix+'_animating');

//Fire afterOpen callback
if (!init) {
settings.afterOpen(trigger);
}
}

function afterClose(trigger, parent) {
el.attr('aria-hidden','true');
items.attr('tabindex', '-1');
$this._setVisAttr(el, true);
el.hide(); //jQuery 1.7 bug fix

$(trigger).removeClass(prefix+'_animating');
$(parent).removeClass(prefix+'_animating');

//Fire init or afterClose callback
if (!init){
settings.afterClose(trigger);
} else if (trigger == 'init'){
settings.init();
}
}

if (el.hasClass(prefix+'_hidden')) {
el.removeClass(prefix+'_hidden');
//Fire beforeOpen callback
if (!init) {
settings.beforeOpen(trigger);
}
el.slideDown(duration, settings.easingOpen, function(){

$(trigger).removeClass(prefix+'_animating');
$(parent).removeClass(prefix+'_animating');

//Fire afterOpen callback
if (!init) {
settings.afterOpen(trigger);
}
});
if (!init) {
settings.beforeOpen(trigger);
}
if (settings.animations === 'jquery') {
el.stop(true,true).slideDown(duration, settings.easingOpen, function(){
afterOpen(trigger, parent);
});
} else if(settings.animations === 'velocity') {
el.velocity("finish").velocity("slideDown", {
easing: settings.easingOpen,
complete: function() {
afterOpen(trigger, parent);
}
});
}
el.attr('aria-hidden','false');
items.attr('tabindex', '0');
$this._setVisAttr(el, false);
Expand All @@ -361,22 +391,19 @@
settings.beforeClose(trigger);
}

el.slideUp(duration, this.settings.easingClose, function() {
el.attr('aria-hidden','true');
items.attr('tabindex', '-1');
$this._setVisAttr(el, true);
el.hide(); //jQuery 1.7 bug fix

$(trigger).removeClass(prefix+'_animating');
$(parent).removeClass(prefix+'_animating');

//Fire init or afterClose callback
if (!init){
settings.afterClose(trigger);
} else if (trigger == 'init'){
settings.init();
}
});
if (settings.animations === 'jquery') {
el.stop(true,true).slideUp(duration, this.settings.easingClose, function() {
afterClose(trigger, parent)
});
} else if (settings.animations === 'velocity') {

el.velocity("finish").velocity("slideUp", {
easing: settings.easingClose,
complete: function() {
afterClose(trigger, parent);
}
});
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.slicknav.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/slicknav.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* SlickNav Responsive Mobile Menu v1.0.7
* SlickNav Responsive Mobile Menu v1.0.8
* (c) 2016 Josh Cope
* licensed under MIT
*/
Expand Down
Loading

0 comments on commit 3ed9280

Please sign in to comment.