Last active
February 27, 2017 20:22
-
-
Save morganestes/138a6918c2bb9ddb8fedcd7bf426854b to your computer and use it in GitHub Desktop.
Add HTML classes to body element when window resizes
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
| /** | |
| * Add classes to the DOM based on the current media query size defined by Foundation breakpoints. | |
| */ | |
| (function fdnMQClasses( window, document, $, undefined ) { | |
| var foundationPrefix = 'fdn-size-'; | |
| // Add the class on page load. | |
| $( document ).ready( function () { | |
| $( 'body' ).addClass( foundationPrefix + Foundation.MediaQuery.current ); | |
| } ); | |
| // Change the class when the mediaquery is updated. | |
| $( window ).on( 'changed.zf.mediaquery', function ( event, newSize, oldSize ) { | |
| // Bail early if nothing's changed. | |
| if ( newSize === oldSize ) { | |
| return; | |
| } | |
| $( 'body' ).removeClass( foundationPrefix + oldSize ).addClass( foundationPrefix + newSize ); | |
| } ); | |
| })( window, document, jQuery, null ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment