| 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 | if( $( '#content' ).height() < $( window ).height() && $( '#sidebar' )[0].scrollHeight > $( window ).height() ) {
|
|---|
| 12 | $( '#content' ).height( $( '#sidebar' ).height() );
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | var sidebar_scrollheight = $( '#sidebar' )[0].scrollHeight;
|
|---|
| 16 | var content_scrollheight = $( '#content' )[0].scrollHeight;
|
|---|
| 17 | var ratio = sidebar_scrollheight / content_scrollheight;
|
|---|
| 18 | var window_height = $( window ).height();
|
|---|
| 19 | var offset = content_scrollheight - window_height;
|
|---|
| 20 | var multiplier = content_scrollheight / offset;
|
|---|
| 21 |
|
|---|
| 22 | if( $( window ).width() > 967 ) {
|
|---|
| 23 | $( '#sidebar' ).css( 'overflow', 'hidden' );
|
|---|
| 24 | $( window ).scroll( function() {
|
|---|
| 25 | var content_position = $( window ).scrollTop();
|
|---|
| 26 | var sidebar_position = ( content_position >= 0 ? Math.round( content_position * ratio * multiplier ) : 0 );
|
|---|
| 27 | $( '#sidebar' ).scrollTop( Math.abs( sidebar_position ) );
|
|---|
| 28 | } );
|
|---|
| 29 | }
|
|---|
| 30 | } );
|
|---|
| 31 | </script>
|
|---|
| 32 | <?php
|
|---|
| 33 | }
|
|---|
| 34 | add_action( 'wp_head', 'tf_script' );
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | function tf_add_jquery() {
|
|---|
| 38 | wp_enqueue_script( 'jquery' );
|
|---|
| 39 | }
|
|---|
| 40 | add_action( 'wp_enqueue_scripts', 'tf_add_jquery' );
|
|---|