Skip to content

Instantly share code, notes, and snippets.

@sugarshin
Created March 28, 2014 08:35
Show Gist options
  • Save sugarshin/9828018 to your computer and use it in GitHub Desktop.
Save sugarshin/9828018 to your computer and use it in GitHub Desktop.
aside.js
$(function() {
var $window = $(window),
$info = $('#info'),
offset = $info.offset(),
rightV = rightVal();
function rightVal() {
return ($window.width() - 960) / 2;
}
$window.resize(function() {
rightV = rightVal();
$info.css('right', rightV);
});
$window.scroll(function() {
if( $(window).scrollTop() > offset.top - 36 ) {
$info.css({
position: 'fixed',
top: 0,
right: rightV
});
} else {
$info.css({
position: 'static',
top: 'auto',
right: 'auto'
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment