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_height = $( '#sidebar' )[0].scrollHeight; //608 |
---|
13 | var content_height = $( '#content' )[0].scrollHeight; //582 |
---|
14 | var ratio = sidebar_height / content_height; |
---|
15 | |
---|
16 | $( window ).scroll( function() { |
---|
17 | var content_position = $( window ).scrollTop(); |
---|
18 | var sidebar_position = content_position * ratio; |
---|
19 | $( '#sidebar' ).scrollTop( sidebar_position ); |
---|
20 | } ); |
---|
21 | } ); |
---|
22 | </script> |
---|
23 | <?php |
---|
24 | } |
---|
25 | add_action( 'wp_head', 'tf_script' ); |
---|
26 | |
---|
27 | |
---|
28 | function tf_add_jquery() { |
---|
29 | wp_enqueue_script( 'jquery' ); |
---|
30 | } |
---|
31 | add_action( 'wp_enqueue_scripts', 'tf_add_jquery' ); |
---|