|
1 | 1 | /*!
|
2 |
| - * jQuery Rellax Plugin v0.3.1 |
| 2 | + * jQuery Rellax Plugin v0.3.2 |
3 | 3 | * Examples and documentation at http://pixelgrade.github.io/rellax/
|
4 | 4 | * Copyright (c) 2016 PixelGrade http://www.pixelgrade.com
|
5 | 5 | * Licensed under MIT http://www.opensource.org/licenses/mit-license.php/
|
|
39 | 39 | constructor: Rellax,
|
40 | 40 | _reloadElement: function() {
|
41 | 41 | this.$el.removeAttr( 'style' );
|
42 |
| - this.$el.removeClass( 'rellax-element' ); |
43 | 42 |
|
44 | 43 | this.offset = this.$el.offset();
|
45 | 44 | this.height = this.$el.outerHeight();
|
|
48 | 47 | this.offset.top -= this.options.bleed;
|
49 | 48 | this.height += 2 * this.options.bleed;
|
50 | 49 |
|
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 |
| - |
56 | 50 | if ( this.parent === undefined && this.$parent.length ) {
|
57 | 51 | var parentHeight = this.$parent.outerHeight();
|
58 | 52 |
|
59 | 53 | this.height = windowHeight - ( windowHeight - parentHeight ) * ( 1 - this.options.amount );
|
60 | 54 | this.offset.top = ( parentHeight - this.height ) / 2;
|
61 | 55 | }
|
62 | 56 | },
|
| 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 | + }, |
63 | 70 | _prepareElement: function() {
|
64 | 71 | if ( this.parent == undefined ) {
|
65 | 72 | this.$el.addClass( 'rellax-element' );
|
66 | 73 | this.$el.css({
|
67 | 74 | position: 'fixed',
|
68 |
| - left: this.offset.left, |
69 | 75 | top: this.offset.top,
|
| 76 | + left: this.offset.left, |
70 | 77 | width: this.width,
|
71 | 78 | height: this.height
|
72 | 79 | });
|
73 | 80 | } else {
|
| 81 | + this._scaleElement(); |
74 | 82 | this.$el.css({
|
75 | 83 | position: 'absolute',
|
76 | 84 | top: this.offset.top,
|
| 85 | + left: this.offset.left, |
| 86 | + width: this.width, |
77 | 87 | height: this.height
|
78 | 88 | });
|
79 | 89 | }
|
|
148 | 158 | var $window = $( window ),
|
149 | 159 | windowWidth = window.innerWidth,
|
150 | 160 | windowHeight = window.innerHeight ,
|
151 |
| - lastScrollY = window.scrollY, |
| 161 | + lastScrollY = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0), |
152 | 162 | frameRendered = true,
|
153 | 163 | elements = [];
|
154 | 164 |
|
|
191 | 201 | updateAll( true );
|
192 | 202 | }
|
193 | 203 |
|
194 |
| - var restart = throttle(badRestart, 1000); |
| 204 | + var restart = throttle(badRestart, 300); |
195 | 205 |
|
196 | 206 | function throttle(fn, threshhold, scope) {
|
197 | 207 | threshhold || (threshhold = 250);
|
|
230 | 240 |
|
231 | 241 | $window.on( 'scroll', function() {
|
232 | 242 | if ( frameRendered === true ) {
|
233 |
| - lastScrollY = window.scrollY; |
| 243 | + lastScrollY = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0); |
234 | 244 | }
|
235 | 245 | frameRendered = false;
|
236 | 246 | });
|
|
0 commit comments