| 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 |
|
|---|
| 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 | if( window_height < content_scrollheight ) {
|
|---|
| 20 | $( '#sidebar' ).css( 'overflow', 'hidden' );
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | $( window ).scroll( function() {
|
|---|
| 24 | var content_position = $( window ).scrollTop();
|
|---|
| 25 | var sidebar_position = ( content_position >= 0 ? Math.round( content_position * ratio * multiplier ) : 0 );
|
|---|
| 26 | $( '#sidebar' ).scrollTop( Math.abs( sidebar_position ) );
|
|---|
| 27 | } );
|
|---|
| 28 | } );
|
|---|
| 29 | </script>
|
|---|
| 30 | <?php
|
|---|
| 31 | }
|
|---|
| 32 | add_action( 'wp_head', 'tf_script' );
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | function tf_add_jquery() {
|
|---|
| 36 | wp_enqueue_script( 'jquery' );
|
|---|
| 37 | }
|
|---|
| 38 | add_action( 'wp_enqueue_scripts', 'tf_add_jquery' );
|
|---|