Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yellowberri-snippets/8047561 to your computer and use it in GitHub Desktop.
Save yellowberri-snippets/8047561 to your computer and use it in GitHub Desktop.
JS: JQUERY: breakSetup - Run Code Based on Break Points
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