Skip to content

Commit 14268b3

Browse files
committed
Add IE fallbacks
1 parent d2fe17f commit 14268b3

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

jquery.rellax.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Rellax Plugin v0.3.1
2+
* jQuery Rellax Plugin v0.3.2
33
* Examples and documentation at http://pixelgrade.github.io/rellax/
44
* Copyright (c) 2016 PixelGrade http://www.pixelgrade.com
55
* Licensed under MIT http://www.opensource.org/licenses/mit-license.php/
@@ -39,7 +39,6 @@
3939
constructor: Rellax,
4040
_reloadElement: function() {
4141
this.$el.removeAttr( 'style' );
42-
this.$el.removeClass( 'rellax-element' );
4342

4443
this.offset = this.$el.offset();
4544
this.height = this.$el.outerHeight();
@@ -48,32 +47,43 @@
4847
this.offset.top -= this.options.bleed;
4948
this.height += 2 * this.options.bleed;
5049

51-
if ( this.parent !== undefined ) {
52-
this.height = windowHeight - ( windowHeight - this.parent.height ) * ( 1 - this.options.amount );
53-
this.offset.top = ( this.parent.height - this.height ) / 2;
54-
}
55-
5650
if ( this.parent === undefined && this.$parent.length ) {
5751
var parentHeight = this.$parent.outerHeight();
5852

5953
this.height = windowHeight - ( windowHeight - parentHeight ) * ( 1 - this.options.amount );
6054
this.offset.top = ( parentHeight - this.height ) / 2;
6155
}
6256
},
57+
_scaleElement: function() {
58+
var parentHeight = this.$parent.outerHeight(),
59+
parentWidth = this.$parent.outerWidth(),
60+
scaleY = parentHeight / this.height,
61+
scaleX = parentWidth / this.width,
62+
scale = Math.max(scaleX, scaleY);
63+
64+
this.width = this.width * scale;
65+
this.height = this.height * scale;
66+
67+
this.offset.top = ( parentHeight - this.height ) / 2;
68+
this.offset.left = ( parentWidth - this.width ) / 2;
69+
},
6370
_prepareElement: function() {
6471
if ( this.parent == undefined ) {
6572
this.$el.addClass( 'rellax-element' );
6673
this.$el.css({
6774
position: 'fixed',
68-
left: this.offset.left,
6975
top: this.offset.top,
76+
left: this.offset.left,
7077
width: this.width,
7178
height: this.height
7279
});
7380
} else {
81+
this._scaleElement();
7482
this.$el.css({
7583
position: 'absolute',
7684
top: this.offset.top,
85+
left: this.offset.left,
86+
width: this.width,
7787
height: this.height
7888
});
7989
}
@@ -148,7 +158,7 @@
148158
var $window = $( window ),
149159
windowWidth = window.innerWidth,
150160
windowHeight = window.innerHeight ,
151-
lastScrollY = window.scrollY,
161+
lastScrollY = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0),
152162
frameRendered = true,
153163
elements = [];
154164

@@ -191,7 +201,7 @@
191201
updateAll( true );
192202
}
193203

194-
var restart = throttle(badRestart, 1000);
204+
var restart = throttle(badRestart, 300);
195205

196206
function throttle(fn, threshhold, scope) {
197207
threshhold || (threshhold = 250);
@@ -230,7 +240,7 @@
230240

231241
$window.on( 'scroll', function() {
232242
if ( frameRendered === true ) {
233-
lastScrollY = window.scrollY;
243+
lastScrollY = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0);
234244
}
235245
frameRendered = false;
236246
});

0 commit comments

Comments
 (0)