Created
March 7, 2013 18:53
-
-
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
This file contains 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 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