@@ -38,41 +38,35 @@ http://www.gnu.org/licenses/gpl.html
3838 if ( arguments . length < 2 || ypos === null ) ypos = "0" ;
3939 if ( arguments . length < 3 || speedFactor === null ) speedFactor = 0.5 ;
4040 if ( arguments . length < 4 || outerHeight === null ) outerHeight = true ;
41+
42+ if ( outerHeight ) {
43+ getHeight = function ( jqo ) {
44+ return jqo . outerHeight ( true ) ;
45+ } ;
46+ } else {
47+ getHeight = function ( jqo ) {
48+ return jqo . height ( ) ;
49+ } ;
50+ }
4151
4252 //get the starting position of each element to have parallax applied to it
4353 function update ( ) {
44-
54+ var pos = $window . scrollTop ( ) ;
55+
4556 $this . each ( function ( ) {
46-
57+ var $element = $ ( this ) ,
58+ top = $element . offset ( ) . top ,
59+ height = getHeight ( $element ) ;
60+
4761 firstTop = $this . offset ( ) . top ;
62+
63+ // Check if totally above or totally below viewport
64+ if ( top + height < pos || top > pos + windowHeight ) {
65+ return ;
66+ }
67+
68+ $this . css ( 'backgroundPosition' , xpos + " " + Math . round ( ypos + ( firstTop - pos ) * speedFactor ) + "px" ) ;
4869 } ) ;
49-
50- if ( outerHeight ) {
51- getHeight = function ( jqo ) {
52- return jqo . outerHeight ( true ) ;
53- } ;
54- } else {
55- getHeight = function ( jqo ) {
56- return jqo . height ( ) ;
57- } ;
58- }
59-
60- // function to be called whenever the window is scrolled or resized
61-
62- var pos = $window . scrollTop ( ) ;
63-
64- $this . each ( function ( ) {
65- var $element = $ ( this ) ,
66- top = $element . offset ( ) . top ,
67- height = getHeight ( $element ) ;
68-
69- // Check if totally above or totally below viewport
70- if ( top + height < pos || top > pos + windowHeight ) {
71- return ;
72- }
73-
74- $this . css ( 'backgroundPosition' , xpos + " " + Math . round ( ypos + ( firstTop - pos ) * speedFactor ) + "px" ) ;
75- } ) ;
7670 }
7771
7872 $window . bind ( 'scroll resize' , update ) ;
0 commit comments