ÿþ/ * * 
 
   *   j q u e r y . s c r o l l F o l l o w . j s 
 
   *   C o p y r i g h t   ( c )   2 0 0 8   N e t   P e r s p e c t i v e   ( h t t p : / / k i t c h e n . n e t - p e r s p e c t i v e . c o m / ) 
 
   *   L i c e n s e d   u n d e r   t h e   M I T   L i c e n s e   ( h t t p : / / w w w . o p e n s o u r c e . o r g / l i c e n s e s / m i t - l i c e n s e . p h p ) 
 
   *   
 
   *   @ a u t h o r   R . A .   R a y 
 
   * 
 
   *   @ p r o j e c t D e s c r i p t i o n 	 j Q u e r y   p l u g i n   f o r   a l l o w i n g   a n   e l e m e n t   t o   a n i m a t e   d o w n   a s   t h e   u s e r   s c r o l l s   t h e   p a g e . 
 
   *   
 
   *   @ v e r s i o n   0 . 4 . 0 
 
   *   
 
   *   @ r e q u i r e s   j q u e r y . j s   ( t e s t e d   w i t h   1 . 2 . 6 ) 
 
   *   @ r e q u i r e s   u i . c o r e . j s   ( t e s t e d   w i t h   1 . 5 . 2 ) 
 
   *   
 
   *   @ o p t i o n a l   j q u e r y . c o o k i e . j s   ( h t t p : / / w w w . s t i l b u e r o . d e / 2 0 0 6 / 0 9 / 1 7 / c o o k i e - p l u g i n - f o r - j q u e r y / ) 
 
   *   @ o p t i o n a l   j q u e r y . e a s i n g . j s   ( h t t p : / / g s g d . c o . u k / s a n d b o x / j q u e r y / e a s i n g /   -   t e s t e d   w i t h   1 . 3 ) 
 
   *   
 
   *   @ p a r a m   s p e e d 	 	 i n t   -   D u r a t i o n   o f   a n i m a t i o n   ( i n   m i l l i s e c o n d s ) 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   5 0 0 
 
   *   @ p a r a m   o f f s e t 	 	 	 i n t   -   N u m b e r   o f   p i x e l s   b o x   s h o u l d   r e m a i n   f r o m   t o p   o f   v i e w p o r t 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   0 
 
   *   @ p a r a m   e a s i n g 	 	 s t r i n g   -   A n y   o n e   o f   t h e   e a s i n g   o p t i o n s   f r o m   t h e   e a s i n g   p l u g i n   -   R e q u i r e s   j Q u e r y   E a s i n g   P l u g i n   <   h t t p : / / g s g d . c o . u k / s a n d b o x / j q u e r y / e a s i n g /   > 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   ' l i n e a r ' 
 
   *   @ p a r a m   c o n t a i n e r 	 s t r i n g   -   I D   o f   t h e   c o n t a i n i n g   d i v 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   b o x ' s   i m m e d i a t e   p a r e n t 
 
   *   @ p a r a m   k i l l S w i t c h 	 s t r i n g   -   I D   o f   t h e   O n / O f f   t o g g l e   e l e m e n t 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   ' k i l l S w i t c h ' 
 
   *   @ p a r a m   o n T e x t 	 	 s t r i n g   -   k i l l S w i t c h   t e x t   t o   b e   d i s p l a y e d   i f   s l i d i n g   i s   e n a b l e d 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   ' T u r n   S l i d e   O f f ' 
 
   *   @ p a r a m   o f f T e x t 	 	 s t r i n g   -   k i l l S w i t c h   t e x t   t o   b e   d i s p l a y e d   i f   s l i d i n g   i s   d i s a b l e d 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   ' T u r n   S l i d e   O n ' 
 
   *   @ p a r a m   r e l a t i v e T o 	 s t r i n g   -   S c r o l l   a n i m a t i o n   c a n   b e   r e l a t i v e   t o   e i t h e r   t h e   ' t o p '   o r   ' b o t t o m '   o f   t h e   v i e w p o r t 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   ' t o p ' 
 
   *   @ p a r a m   d e l a y 	 	 	 i n t   -   T i m e   b e t w e e n   t h e   e n d   o f   t h e   s c r o l l   a n d   t h e   b e g i n n i n g   o f   t h e   a n i m a t i o n   i n   m i l l i s e c o n d s 
 
   *   	 	 	 	 	 	 	 	 d e f a u l t :   0 
 
   * / 
 
 
 
 (   f u n c t i o n (   $   )   { 
 
 	 
 
 	 $ . s c r o l l F o l l o w   =   f u n c t i o n   (   b o x ,   o p t i o n s   ) 
 
 	 {   
 
 	 	 / /   C o n v e r t   b o x   i n t o   a   j Q u e r y   o b j e c t 
 
 	 	 b o x   =   $ (   b o x   ) ; 
 
 	 	 
 
 	 	 / /   ' b o x '   i s   t h e   o b j e c t   t o   b e   a n i m a t e d 
 
 	 	 v a r   p o s i t i o n   =   b o x . c s s (   ' p o s i t i o n '   ) ; 
 
 	 	 
 
 	 	 f u n c t i o n   a n i ( ) 
 
 	 	 { 	 	 
 
 	 	 	 / /   T h e   s c r i p t   r u n s   o n   e v e r y   s c r o l l   w h i c h   r e a l l y   m e a n s   m a n y   t i m e s   d u r i n g   a   s c r o l l . 
 
 	 	 	 / /   W e   d o n ' t   w a n t   m u l t i p l e   s l i d e s   t o   q u e u e   u p . 
 
 	 	 	 b o x . q u e u e (   [   ]   ) ; 
 
 	 	 
 
 	 	 	 / /   A   b u n c h   o f   v a l u e s   w e   n e e d   t o   d e t e r m i n e   w h e r e   t o   a n i m a t e   t o 
 
 	 	 	 v a r   v i e w p o r t H e i g h t   =   p a r s e I n t (   $ (   w i n d o w   ) . h e i g h t ( )   ) ; 	 
 
 	 	 	 v a r   p a g e S c r o l l   =     p a r s e I n t (   $ (   d o c u m e n t   ) . s c r o l l T o p ( )   ) ; 
 
 	 	 	 v a r   p a r e n t T o p   =     p a r s e I n t (   b o x . c o n t . o f f s e t ( ) . t o p   ) ; 
 
 	 	 	 v a r   p a r e n t H e i g h t   =   p a r s e I n t (   b o x . c o n t . a t t r (   ' o f f s e t H e i g h t '   )   ) ; 
 
 	 	 	 v a r   b o x H e i g h t   =   p a r s e I n t (   b o x . a t t r (   ' o f f s e t H e i g h t '   )   +   (   p a r s e I n t (   b o x . c s s (   ' m a r g i n T o p '   )   )   | |   0   )   +   (   p a r s e I n t (   b o x . c s s (   ' m a r g i n B o t t o m '   )   )   | |   0   )   ) ; 
 
 	 	 	 v a r   a n i T o p ; 
 
 	 	 	 
 
 	 	 	 / /   M a k e   s u r e   t h e   u s e r   w a n t s   t h e   a n i m a t i o n   t o   h a p p e n 
 
 	 	 	 i f   (   i s A c t i v e   ) 
 
 	 	 	 { 
 
 	 	 	 	 / /   I f   t h e   b o x   s h o u l d   a n i m a t e   r e l a t i v e   t o   t h e   t o p   o f   t h e   w i n d o w 
 
 	 	 	 	 i f   (   o p t i o n s . r e l a t i v e T o   = =   ' t o p '   ) 
 
 	 	 	 	 { 
 
 	 	 	 	 	 / /   D o n ' t   a n i m a t e   u n t i l   t h e   t o p   o f   t h e   w i n d o w   i s   c l o s e   e n o u g h   t o   t h e   t o p   o f   t h e   b o x 
 
 	 	 	 	 	 i f   (   b o x . i n i t i a l O f f s e t T o p   > =   (   p a g e S c r o l l   +   o p t i o n s . o f f s e t   )   ) 
 
 	 	 	 	 	 { 
 
 	 	 	 	 	 	 a n i T o p   =   b o x . i n i t i a l T o p ; 
 
 	 	 	 	 	 } 
 
 	 	 	 	 	 e l s e 
 
 	 	 	 	 	 { 
 
 	 	 	 	 	 	 a n i T o p   =   M a t h . m i n (   (   M a t h . m a x (   (   - p a r e n t T o p   ) ,   (   p a g e S c r o l l   -   b o x . i n i t i a l O f f s e t T o p   +   b o x . i n i t i a l T o p   )   )   +   o p t i o n s . o f f s e t   ) ,   (   p a r e n t H e i g h t   -   b o x H e i g h t   -   b o x . p a d d i n g A d j u s t m e n t   )   ) ; 
 
 	 	 	 	 	 } 
 
 	 	 	 	 } 
 
 	 	 	 	 / /   I f   t h e   b o x   s h o u l d   a n i m a t e   r e l a t i v e   t o   t h e   b o t t o m   o f   t h e   w i n d o w 
 
 	 	 	 	 e l s e   i f   (   o p t i o n s . r e l a t i v e T o   = =   ' b o t t o m '   ) 
 
 	 	 	 	 { 
 
 	 	 	 	 	 / /   D o n ' t   a n i m a t e   u n t i l   t h e   b o t t o m   o f   t h e   w i n d o w   i s   c l o s e   e n o u g h   t o   t h e   b o t t o m   o f   t h e   b o x 
 
 	 	 	 	 	 i f   (   (   b o x . i n i t i a l O f f s e t T o p   +   b o x H e i g h t   )   > =   (   p a g e S c r o l l   +   o p t i o n s . o f f s e t   +   v i e w p o r t H e i g h t   )   ) 
 
 	 	 	 	 	 { 
 
 	 	 	 	 	 	 a n i T o p   =   b o x . i n i t i a l T o p ; 
 
 	 	 	 	 	 } 
 
 	 	 	 	 	 e l s e 
 
 	 	 	 	 	 { 
 
 	 	 	 	 	 	 a n i T o p   =   M a t h . m i n (   (   p a g e S c r o l l   +   v i e w p o r t H e i g h t   -   b o x H e i g h t   -   o p t i o n s . o f f s e t   ) ,   (   p a r e n t H e i g h t   -   b o x H e i g h t   )   ) ; 
 
 	 	 	 	 	 } 
 
 	 	 	 	 } 
 
 	 	 	 	 
 
 	 	 	 	 / /   C h e c k s   t o   s e e   i f   t h e   r e l e v a n t   s c r o l l   w a s   t h e   l a s t   o n e 
 
 	 	 	 	 / /   " - 2 0 "   i s   t o   a c c o u n t   f o r   i n a c c u r a c y   i n   t h e   t i m e o u t 
 
 	 	 	 	 i f   (   (   n e w   D a t e ( ) . g e t T i m e ( )   -   b o x . l a s t S c r o l l   )   > =   (   o p t i o n s . d e l a y   -   2 0   )   ) 
 
 	 	 	 	 { 
 
 	 	 	 	 	 b o x . a n i m a t e ( 
 
 	 	 	 	 	 	 { 
 
 	 	 	 	 	 	 	 t o p :   a n i T o p 
 
 	 	 	 	 	 	 } ,   o p t i o n s . s p e e d ,   o p t i o n s . e a s i n g 
 
 	 	 	 	 	 ) ; 
 
 	 	 	 	 } 
 
 	 	 	 } 
 
 	 	 } ; 
 
 	 	 
 
 	 	 / /   F o r   u s e r - i n i t i a t e d   s t o p p i n g   o f   t h e   s l i d e 
 
 	 	 v a r   i s A c t i v e   =   t r u e ; 
 
 	 	 
 
 	 	 i f   (   $ . c o o k i e   ! =   u n d e f i n e d   ) 
 
 	 	 { 
 
 	 	 	 i f (   $ . c o o k i e (   ' s c r o l l F o l l o w S e t t i n g '   +   b o x . a t t r (   ' i d '   )   )   = =   ' f a l s e '   ) 
 
 	 	 	 { 
 
 	 	 	 	 v a r   i s A c t i v e   =   f a l s e ; 
 
 	 	 	 	 
 
 	 	 	 	 $ (   ' # '   +   o p t i o n s . k i l l S w i t c h   ) . t e x t (   o p t i o n s . o f f T e x t   ) 
 
 	 	 	 	 	 . t o g g l e (   
 
 	 	 	 	 	 	 f u n c t i o n   ( ) 
 
 	 	 	 	 	 	 { 
 
 	 	 	 	 	 	 	 i s A c t i v e   =   t r u e ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ (   t h i s   ) . t e x t (   o p t i o n s . o n T e x t   ) ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ . c o o k i e (   ' s c r o l l F o l l o w S e t t i n g '   +   b o x . a t t r (   ' i d '   ) ,   t r u e ,   {   e x p i r e s :   3 6 5 ,   p a t h :   ' / ' }   ) ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 a n i ( ) ; 
 
 	 	 	 	 	 	 } , 
 
 	 	 	 	 	 	 f u n c t i o n   ( ) 
 
 	 	 	 	 	 	 { 
 
 	 	 	 	 	 	 	 i s A c t i v e   =   f a l s e ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ (   t h i s   ) . t e x t (   o p t i o n s . o f f T e x t   ) ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 b o x . a n i m a t e ( 
 
 	 	 	 	 	 	 	 	 { 
 
 	 	 	 	 	 	 	 	 	 t o p :   b o x . i n i t i a l T o p 
 
 	 	 	 	 	 	 	 	 } ,   o p t i o n s . s p e e d ,   o p t i o n s . e a s i n g 
 
 	 	 	 	 	 	 	 ) ; 	 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ . c o o k i e (   ' s c r o l l F o l l o w S e t t i n g '   +   b o x . a t t r (   ' i d '   ) ,   f a l s e ,   {   e x p i r e s :   3 6 5 ,   p a t h :   ' / ' }   ) ; 
 
 	 	 	 	 	 	 } 
 
 	 	 	 	 	 ) ; 
 
 	 	 	 } 
 
 	 	 	 e l s e 
 
 	 	 	 { 
 
 	 	 	 	 $ (   ' # '   +   o p t i o n s . k i l l S w i t c h   ) . t e x t (   o p t i o n s . o n T e x t   ) 
 
 	 	 	 	 	 . t o g g l e (   
 
 	 	 	 	 	 	 f u n c t i o n   ( ) 
 
 	 	 	 	 	 	 { 
 
 	 	 	 	 	 	 	 i s A c t i v e   =   f a l s e ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ (   t h i s   ) . t e x t (   o p t i o n s . o f f T e x t   ) ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 b o x . a n i m a t e ( 
 
 	 	 	 	 	 	 	 	 { 
 
 	 	 	 	 	 	 	 	 	 t o p :   b o x . i n i t i a l T o p 
 
 	 	 	 	 	 	 	 	 } ,   0 
 
 	 	 	 	 	 	 	 ) ; 	 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ . c o o k i e (   ' s c r o l l F o l l o w S e t t i n g '   +   b o x . a t t r (   ' i d '   ) ,   f a l s e ,   {   e x p i r e s :   3 6 5 ,   p a t h :   ' / ' }   ) ; 
 
 	 	 	 	 	 	 } , 
 
 	 	 	 	 	 	 f u n c t i o n   ( ) 
 
 	 	 	 	 	 	 { 
 
 	 	 	 	 	 	 	 i s A c t i v e   =   t r u e ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ (   t h i s   ) . t e x t (   o p t i o n s . o n T e x t   ) ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 $ . c o o k i e (   ' s c r o l l F o l l o w S e t t i n g '   +   b o x . a t t r (   ' i d '   ) ,   t r u e ,   {   e x p i r e s :   3 6 5 ,   p a t h :   ' / ' }   ) ; 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 a n i ( ) ; 
 
 	 	 	 	 	 	 } 
 
 	 	 	 	 	 ) ; 
 
 	 	 	 } 
 
 	 	 } 
 
 	 	 
 
 	 	 / /   I f   n o   p a r e n t   I D   w a s   s p e c i f i e d ,   a n d   t h e   i m m e d i a t e   p a r e n t   d o e s   n o t   h a v e   a n   I D 
 
 	 	 / /   o p t i o n s . c o n t a i n e r   w i l l   b e   u n d e f i n e d .   S o   w e   n e e d   t o   f i g u r e   o u t   t h e   p a r e n t   e l e m e n t . 
 
 	 	 i f   (   o p t i o n s . c o n t a i n e r   = =   ' ' ) 
 
 	 	 { 
 
 	 	 	 b o x . c o n t   =   b o x . p a r e n t ( ) ; 
 
 	 	 } 
 
 	 	 e l s e 
 
 	 	 { 
 
 	 	 	 b o x . c o n t   =   $ (   ' # '   +   o p t i o n s . c o n t a i n e r   ) ; 
 
 	 	 } 
 
 	 	 
 
 	 	 / /   F i n d s   t h e   d e f a u l t   p o s i t i o n i n g   o f   t h e   b o x . 
 
 	 	 b o x . i n i t i a l O f f s e t T o p   =     p a r s e I n t (   b o x . o f f s e t ( ) . t o p   ) ; 
 
 	 	 b o x . i n i t i a l T o p   =   p a r s e I n t (   b o x . c s s (   ' t o p '   )   )   | |   0 ; 
 
 	 	 
 
 	 	 / /   H a c k   t o   f i x   d i f f e r e n t   t r e a t m e n t   o f   b o x e s   p o s i t i o n e d   ' a b s o l u t e '   a n d   ' r e l a t i v e ' 
 
 	 	 i f   (   b o x . c s s (   ' p o s i t i o n '   )   = =   ' r e l a t i v e '   ) 
 
 	 	 { 
 
 	 	 	 b o x . p a d d i n g A d j u s t m e n t   =   p a r s e I n t (   b o x . c o n t . c s s (   ' p a d d i n g T o p '   )   )   +   p a r s e I n t (   b o x . c o n t . c s s (   ' p a d d i n g B o t t o m '   )   ) ; 
 
 	 	 } 
 
 	 	 e l s e 
 
 	 	 { 
 
 	 	 	 b o x . p a d d i n g A d j u s t m e n t   =   0 ; 
 
 	 	 } 
 
 	 	 
 
 	 	 / /   A n i m a t e   t h e   b o x   w h e n   t h e   p a g e   i s   s c r o l l e d 
 
 	 	 $ (   w i n d o w   ) . s c r o l l (   f u n c t i o n   ( ) 
 
 	 	 	 { 
 
 	 	 	 	 / /   S e t s   u p   t h e   d e l a y   o f   t h e   a n i m a t i o n 
 
 	 	 	 	 $ . f n . s c r o l l F o l l o w . i n t e r v a l   =   s e t T i m e o u t (   f u n c t i o n ( ) {   a n i ( ) ; }   ,   o p t i o n s . d e l a y   ) ; 
 
 	 	 	 	 
 
 	 	 	 	 / /   T o   c h e c k   a g a i n s t   r i g h t   b e f o r e   s e t t i n g   t h e   a n i m a t i o n 
 
 	 	 	 	 b o x . l a s t S c r o l l   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
 	 	 	 } 
 
 	 	 ) ; 
 
 	 	 
 
 	 	 / /   A n i m a t e   t h e   b o x   w h e n   t h e   p a g e   i s   r e s i z e d 
 
 	 	 $ (   w i n d o w   ) . r e s i z e (   f u n c t i o n   ( ) 
 
 	 	 	 { 
 
 	 	 	 	 / /   S e t s   u p   t h e   d e l a y   o f   t h e   a n i m a t i o n 
 
 	 	 	 	 $ . f n . s c r o l l F o l l o w . i n t e r v a l   =   s e t T i m e o u t (   f u n c t i o n ( ) {   a n i ( ) ; }   ,   o p t i o n s . d e l a y   ) ; 
 
 	 	 	 	 
 
 	 	 	 	 / /   T o   c h e c k   a g a i n s t   r i g h t   b e f o r e   s e t t i n g   t h e   a n i m a t i o n 
 
 	 	 	 	 b o x . l a s t S c r o l l   =   n e w   D a t e ( ) . g e t T i m e ( ) ; 
 
 	 	 	 } 
 
 	 	 ) ; 
 
 
 
 	 	 / /   R u n   a n   i n i t i a l   a n i m a t i o n   o n   p a g e   l o a d 
 
 	 	 b o x . l a s t S c r o l l   =   0 ; 
 
 	 	 
 
 	 	 a n i ( ) ; 
 
 	 } ; 
 
 	 
 
 	 $ . f n . s c r o l l F o l l o w   =   f u n c t i o n   (   o p t i o n s   ) 
 
 	 { 
 
 	 	 o p t i o n s   =   o p t i o n s   | |   { } ; 
 
 	 	 o p t i o n s . r e l a t i v e T o   =   o p t i o n s . r e l a t i v e T o   | |   ' t o p ' ; 
 
 	 	 o p t i o n s . s p e e d   =   o p t i o n s . s p e e d   | |   5 0 0 ; 
 
 	 	 o p t i o n s . o f f s e t   =   o p t i o n s . o f f s e t   | |   0 ; 
 
 	 	 o p t i o n s . e a s i n g   =   o p t i o n s . e a s i n g   | |   ' s w i n g ' ; 
 
 	 	 o p t i o n s . c o n t a i n e r   =   o p t i o n s . c o n t a i n e r   | |   t h i s . p a r e n t ( ) . a t t r (   ' i d '   ) ; 
 
 	 	 o p t i o n s . k i l l S w i t c h   =   o p t i o n s . k i l l S w i t c h   | |   ' k i l l S w i t c h ' ; 
 
 	 	 o p t i o n s . o n T e x t   =   o p t i o n s . o n T e x t   | |   ' T u r n   S l i d e   O f f ' ; 
 
 	 	 o p t i o n s . o f f T e x t   =   o p t i o n s . o f f T e x t   | |   ' T u r n   S l i d e   O n ' ; 
 
 	 	 o p t i o n s . d e l a y   =   o p t i o n s . d e l a y   | |   0 ; 
 
 	 	 
 
 	 	 t h i s . e a c h (   f u n c t i o n ( )   
 
 	 	 	 { 
 
 	 	 	 	 n e w   $ . s c r o l l F o l l o w (   t h i s ,   o p t i o n s   ) ; 
 
 	 	 	 } 
 
 	 	 ) ; 
 
 	 	 
 
 	 	 r e t u r n   t h i s ; 
 
 	 } ; 
 
 } ) (   j Q u e r y   ) ; 
 
 
 
 
 
 
