| 1 | |
| 2 | jQuery(document).ready(function($){ |
| 3 | |
| 4 | var $secondary = $( '#secondary' ), |
| 5 | $window = $( window ); |
| 6 | |
| 7 | $secondary.css( 'position', 'relative' ); |
| 8 | |
| 9 | $window.scroll( function() { |
| 10 | var offset = window.pageYOffset; |
| 11 | |
| 12 | // Avoid awkward positions for Webkit 'springy' scrolling. |
| 13 | if ( offset < 0 ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | // Don't force it down past the bottom of the page. |
| 18 | if ( offset + $window.height() > $(document).height() ) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | if ( $secondary.height() <= $window.height() ) { |
| 23 | |
| 24 | $secondary.css( 'top', offset ); |
| 25 | |
| 26 | } else { |
| 27 | |
| 28 | if ( ( offset + $window.height() ) > ( $secondary.position().top + $secondary.height() + $secondary.offsetParent().offset().top ) ) { |
| 29 | secondaryOffset = offset + $window.height() - $secondary.height() - $secondary.offsetParent().offset().top; |
| 30 | $secondary.css( 'top', secondaryOffset ); |
| 31 | } else if ( offset < $secondary.position().top ) { |
| 32 | $secondary.css( 'top', offset ); |
| 33 | } |
| 34 | |
| 35 | } |
| 36 | |
| 37 | }); |
| 38 | }); |