Skip to content

Instantly share code, notes, and snippets.

@msutkowski
Created March 7, 2013 18:53
Show Gist options
  • Save msutkowski/5110685 to your computer and use it in GitHub Desktop.
Save msutkowski/5110685 to your computer and use it in GitHub Desktop.
Will dynamically return a predetermined offset based on the window size for the affix plugin
var adjustAffixOffset = (function() {
var $stickyItem = $('.stickyform'),
defaultOffsetValue = 220,
init = function() {
changeOffsetValue();
initAffixEvent();
initAffixPlugin();
initAffixResize();
},
changeOffsetValue = function() {
var ws = $(window).innerWidth();
if( ws <= 980 ) n = 200;
else n = 135;
return n;
},
logOffsetValue = function() {
console.log(n);
},
initAffixEvent = function() {
$(window).on( 'resize', function( event ) {
initAffixPlugin();
logOffsetValue();
});
},
initAffixPlugin = function() {
setTimeout( function() {
$stickyItem.affix({offset: {top: changeOffsetValue}});
});
},
initAffixResize = function() {
$(window).load(function() {
changeOffsetValue();
initAffixPlugin();
//logOffsetValue();
});
};
return { init: init };
})();
if($.browser.msie && $.browser.version <= 7){
//Do nothing
}else{
adjustAffixOffset.init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment