Created
June 10, 2016 14:32
-
-
Save yratof/814cab0adb90ae7355603970b85a1193 to your computer and use it in GitHub Desktop.
jQuery – Off-canvas reveal class applier
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
var canvas_reveal = function ( container, link_element ) { | |
var element_active = false; | |
var toggle_element = function() { | |
if ( element_active ) { | |
container | |
.addClass( 'closed' ) | |
.removeClass( 'open' ); | |
element_active = false; | |
} | |
else { | |
container | |
.addClass( 'open' ) | |
.removeClass( 'closed' ); | |
setTimeout( function() { | |
element_active = true; | |
}, 200 ); | |
} | |
}; | |
// Open cart | |
link_element.on( 'click', function( e ) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
toggle_element(); | |
} ); | |
// Close cart | |
$( document ).click( function() { | |
if ( true == element_active ) { | |
toggle_element(); | |
} | |
} ); | |
container.click( function( e ) { | |
e.stopPropagation(); | |
} ); | |
} | |
canvas_reveal( | |
$( '.trigger' ), // Off-canvas element | |
$( '.target' ) // Trigger | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment