Figured since I registered I should at least contribute once, here's a script I wrote to enable a sidebar on a site written for a college project to travel up and down the page with the user. This is just used with a floated element, I used the aside element and floated it next to the main element.
You can see it in practice here: http://abelnet.net/web3/cfnorg/
Should note that this requires jquery on the website its used on.
You can see it in practice here: http://abelnet.net/web3/cfnorg/
- Code:
<style>
aside{
transition: all 0.4s ease;
}
</style>
<script>
$(document).ready(function() {
// Prepare the original position inside a variable.
var tOrigin = $('aside').offset()
// Bind an anonymous function to the browser scroll event.
$(window).bind('scroll', function(){
if ($(window).scrollTop() > $('#headerWrapper').height()) {
var tPos = $(window).scrollTop() + 25;
$('aside').offset({top: tPos})
} else {
$('aside').offset({top: tOrigin.top})
}
});
});
</script>
Should note that this requires jquery on the website its used on.
Last edited by Bricyn on Wed Feb 18, 2015 11:57 pm; edited 1 time in total