Last active
December 31, 2015 21:29
-
-
Save yellowberri-snippets/8047561 to your computer and use it in GitHub Desktop.
JS: JQUERY: breakSetup - Run Code Based on Break Points
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 $state; | |
function breakSetup( $breakwidth, $operator, $callback ) { | |
var w = $(window), | |
$width = w.width(); | |
var operators = { | |
'<' : function( a, b ) { return a < b ; }, | |
'>' : function( a, b ) { return a > b ; }, | |
'<=' : function( a, b ) { return a <= b ; }, | |
'>=' : function( a, b ) { return a >= b ; } | |
}; | |
w.load(function() { | |
if ( operators[ $operator ] ( $width, $breakwidth ) ) { | |
$state = $callback.name; | |
return $callback(); | |
} | |
}); | |
w.resize(function() { | |
$width = w.width(); | |
if ( operators[ $operator ] ( $width, $breakwidth ) ) { | |
if ( $state !== $callback.name ) { | |
$state = $callback.name; | |
return $callback(); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment