PageSourceSearch

https://www.city.saiki.oita.jp/dynamic/common/js/jquery.scrollfollow.js

js city.saiki.oita.jp collected 2026-10-02 04:58:15 UTC 8,142 bytes, 253 lines download raw bytes

1/**
2 * jquery.scrollFollow.js
3 * Copyright (c) 2008 Net Perspective (http://kitchen.net-perspective.com/)
4 * Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
5 * 
6 * @author R.A. Ray
7 *
8 * @projectDescription	jQuery plugin for allowing an element to animate down as the user scrolls the page.
9 * 
10 * @version 0.4.0
11 * 
12 * @requires jquery.js (tested with 1.2.6)
13 * @requires ui.core.js (tested with 1.5.2)
14 * 
15 * @optional jquery.cookie.js (http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/)
16 * @optional jquery.easing.js (http://gsgd.co.uk/sandbox/jquery/easing/ - tested with 1.3)
17 * 
18 * @param speed		int - Duration of animation (in milliseconds)
19 * 								default: 500
20 * @param offset			int - Number of pixels box should remain from top of viewport
21 * 								default: 0
22 * @param easing		string - Any one of the easing options from the easing plugin - Requires jQuery Easing Plugin < http://gsgd.co.uk/sandbox/jquery/easing/ >
23 * 								default: 'linear'
24 * @param container	string - ID of the containing div
25 * 								default: box's immediate parent
26 * @param killSwitch	string - ID of the On/Off toggle element
27 * 								default: 'killSwitch'
28 * @param onText		string - killSwitch text to be displayed if sliding is enabled
29 * 								default: 'Turn Slide Off'
30 * @param offText		string - killSwitch text to be displayed if sliding is disabled
31 * 								default: 'Turn Slide On'
32 * @param relativeTo	string - Scroll animation can be relative to either the 'top' or 'bottom' of the viewport
33 * 								default: 'top'
34 * @param delay			int - Time between the end of the scroll and the beginning of the animation in milliseconds
35 * 								default: 0
36 */
37
38( function( $ ) {
39	
40	$.scrollFollow = function ( box, options )
41	{ 
42		// Convert box into a jQuery object
43		box = $( box );
44		
45		// 'box' is the object to be animated
46		var position = box.css( 'position' );
47		
48		function ani()
49		{		
50			// The script runs on every scroll which really means many times during a scroll.
51			// We don't want multiple slides to queue up.
52			box.queue( [ ] );
53		
54			// A bunch of values we need to determine where to animate to
55			var viewportHeight = parseInt( $( window ).height() );	
56			var pageScroll =  parseInt( $( document ).scrollTop() );
57			var parentTop =  parseInt( box.cont.offset().top );
58			//var parentHeight = parseInt( box.cont.attr( 'offsetHeight' ) );
59			//var boxHeight = parseInt( box.attr( 'offsetHeight' ) + ( parseInt( box.css( 'marginTop' ) ) || 0 ) + ( parseInt( box.css( 'marginBottom' ) ) || 0 ) );
60			var parentHeight = parseInt( box.cont.outerHeight() );
61			var boxHeight = parseInt( box.outerHeight() + ( parseInt( box.css( 'marginTop' ) ) || 0 ) + ( parseInt( box.css( 'marginBottom' ) ) || 0 ) );
62			var aniTop;
63			
64			// Make sure the user wants the animation to happen
65			if ( isActive )
66			{
67				// If the box should animate relative to the top of the window
68				if ( options.relativeTo == 'top' )
69				{
70					// Don't animate until the top of the window is close enough to the top of the box
71					if ( box.initialOffsetTop >= ( pageScroll + options.offset ) )
72					{
73						aniTop = box.initialTop;
74					}
75					else
76					{
77						aniTop = Math.min( ( Math.max( ( -parentTop ), ( pageScroll - box.initialOffsetTop + box.initialTop ) ) + options.offset ), ( parentHeight - boxHeight - box.paddingAdjustment ) );
78					}
79				}
80				// If the box should animate relative to the bottom of the window
81				else if ( options.relativeTo == 'bottom' )
82				{
83					// Don't animate until the bottom of the window is close enough to the bottom of the box
84					if ( ( box.initialOffsetTop + boxHeight ) >= ( pageScroll + options.offset + viewportHeight ) )
85					{
86						aniTop = box.initialTop;
87					}
88					else
89					{
90						aniTop = Math.min( ( pageScroll + viewportHeight - boxHeight - options.offset ), ( parentHeight - boxHeight ) );
91					}
92				}
93				
94				// Checks to see if the relevant scroll was the last one
95				// "-20" is to account for inaccuracy in the timeout
96				if ( ( new Date().getTime() - box.lastScroll ) >= ( options.delay - 20 ) )
97				{
98					box.animate(
99						{
100							top: aniTop
101						}, options.speed, options.easing
102					);
103				}
104			}
105		};
106		
107		// For user-initiated stopping of the slide
108		var isActive = true;
109		
110		if ( $.cookie != undefined )
111		{
112			if( $.cookie( 'scrollFollowSetting' + box.attr( 'id' ) ) == 'false' )
113			{
114				var isActive = false;
115				
116				$( '#' + options.killSwitch ).text( options.offText )
117					.toggle( 
118						function ()
119						{
120							isActive = true;
121							
122							$( this ).text( options.onText );
123							
124							$.cookie( 'scrollFollowSetting' + box.attr( 'id' ), true, { expires: 365, path: '/'} );
125							
126							ani();
127						},
128						function ()
129						{
130							isActive = false;
131							
132							$( this ).text( options.offText );
133							
134							box.animate(
135								{
136									top: box.initialTop
137								}, options.speed, options.easing
138							);	
139							
140							$.cookie( 'scrollFollowSetting' + box.attr( 'id' ), false, { expires: 365, path: '/'} );
141						}
142					);
143			}
144			else
145			{
146				$( '#' + options.killSwitch ).text( options.onText )
147					.toggle( 
148						function ()
149						{
150							isActive = false;
151							
152							$( this ).text( options.offText );
153							
154							box.animate(
155								{
156									top: box.initialTop
157								}, 0
158							);	
159							
160							$.cookie( 'scrollFollowSetting' + box.attr( 'id' ), false, { expires: 365, path: '/'} );
161						},
162						function ()
163						{
164							isActive = true;
165							
166							$( this ).text( options.onText );
167							
168							$.cookie( 'scrollFollowSetting' + box.attr( 'id' ), true, { expires: 365, path: '/'} );
169							
170							ani();
171						}
172					);
173			}
174		}
175		
176		// If no parent ID was specified, and the immediate parent does not have an ID
177		// options.container will be undefined. So we need to figure out the parent element.
178		if ( options.container == '')
179		{
180			box.cont = box.parent();
181		}
182		else
183		{
184			box.cont = $( '#' + options.container );
185		}
186		
187		// Finds the default positioning of the box.
188		box.initialOffsetTop =  parseInt( box.offset().top );
189		box.initialTop = parseInt( box.css( 'top' ) ) || 0;
190		
191		// Hack to fix different treatment of boxes positioned 'absolute' and 'relative'
192		if ( box.css( 'position' ) == 'relative' )
193		{
194			box.paddingAdjustment = parseInt( box.cont.css( 'paddingTop' ) ) + parseInt( box.cont.css( 'paddingBottom' ) );
195		}
196		else
197		{
198			box.paddingAdjustment = 0;
199		}
200		
201		// Animate the box when the page is scrolled
202		$( window ).scroll( function ()
203			{
204				// Sets up the delay of the animation
205				$.fn.scrollFollow.interval = setTimeout( function(){ ani();} , options.delay );
206				
207				// To check against right before setting the animation
208				box.lastScroll = new Date().getTime();
209			}
210		);
211		
212		// Animate the box when the page is resized
213		$( window ).resize( function ()
214			{
215				// Sets up the delay of the animation
216				$.fn.scrollFollow.interval = setTimeout( function(){ ani();} , options.delay );
217				
218				// To check against right before setting the animation
219				box.lastScroll = new Date().getTime();
220			}
221		);
222
223		// Run an initial animation on page load
224		box.lastScroll = 0;
225		
226		ani();
227	};
228	
229	$.fn.scrollFollow = function ( options )
230	{
231		options = options || {};
232		options.relativeTo = options.relativeTo || 'top';
233		options.speed = options.speed || 500;
234		options.offset = options.offset || 0;
235		options.easing = options.easing || 'swing';
236		options.container = options.container || this.parent().attr( 'id' );
237		options.killSwitch = options.killSwitch || 'killSwitch';
238		options.onText = options.onText || 'Turn Slide Off';
239		options.offText = options.offText || 'Turn Slide On';
240		options.delay = options.delay || 0;
241		
242		this.each( function() 
243			{
244				new $.scrollFollow( this, options );
245			}
246		);
247		
248		return this;
249	};
250})( jQuery );
251
252
253

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.