Make WordPress Core

Ticket #29979: twenty-fifteen.4.php

File twenty-fifteen.4.php, 1.0 KB (added by MikeHansenMe, 12 years ago)

add scroll if content is smaller than window

Line 
1<?php
2/*
3Plugin Name: Twenty Fifteen Scroll
4*/
5
6function 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}
32add_action( 'wp_head', 'tf_script' );
33
34
35function tf_add_jquery() {
36 wp_enqueue_script( 'jquery' );
37}
38add_action( 'wp_enqueue_scripts', 'tf_add_jquery' );