1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Twenty Fifteen Scroll |
---|
4 | */ |
---|
5 | |
---|
6 | function tf_script() { |
---|
7 | ?> |
---|
8 | <script type="text/javascript"> |
---|
9 | jQuery( document ).ready( function ( $ ) { |
---|
10 | $( '#sidebar' ).css( 'overflow', 'hidden' ); |
---|
11 | |
---|
12 | var sidebar_scrollheight = $( '#sidebar' )[0].scrollHeight; |
---|
13 | var content_scrollheight = $( '#content' )[0].scrollHeight; |
---|
14 | var ratio = sidebar_scrollheight / content_scrollheight; |
---|
15 | var window_height = $( window ).height(); |
---|
16 | var offset = content_scrollheight - window_height; |
---|
17 | var multiplier = content_scrollheight / offset; |
---|
18 | |
---|
19 | $( window ).scroll( function() { |
---|
20 | var content_position = $( window ).scrollTop(); |
---|
21 | var sidebar_position = ( content_position >= 0 ? Math.round( content_position * ratio * multiplier ) : 0 ); |
---|
22 | $( '#sidebar' ).scrollTop( Math.abs( sidebar_position ) ); |
---|
23 | } ); |
---|
24 | } ); |
---|
25 | </script> |
---|
26 | <?php |
---|
27 | } |
---|
28 | add_action( 'wp_head', 'tf_script' ); |
---|
29 | |
---|
30 | |
---|
31 | function tf_add_jquery() { |
---|
32 | wp_enqueue_script( 'jquery' ); |
---|
33 | } |
---|
34 | add_action( 'wp_enqueue_scripts', 'tf_add_jquery' ); |
---|