Skip to content

Commit ffff9af

Browse files
committed
implement graceful degradation for iOS devices
1 parent e56264a commit ffff9af

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ Note that when specifying these options as html data-attributes, you should conv
8787
<td>0</td>
8888
<td>You can optionally set the parallax mirror element to extend a few pixels above and below the mirrored element. This can hide slow or stuttering scroll events in certain browsers.</td>
8989
</tr>
90+
<tr>
91+
<td>iosFix</td>
92+
<td>boolean</td>
93+
<td>true</td>
94+
<td>iOS devices are incompatable with this plugin. If true, this option will set the parallax image as a static, centered background image whenever it detects an iOS user agent. Disable this if you wish to implement your own graceful degradation.</td>
95+
</tr>
9096
</tbody>
9197
</table>
9298

parallax.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* parallax.js v0.9.1 (http://pixelcog.github.io/parallax.js/)
2+
* parallax.js v1.0 (http://pixelcog.github.io/parallax.js/)
33
* Copyright (c) 2014 PixelCog, Inc.
44
* Licensed under MIT (https://github.com/pixelcog/parallax.js/blob/master/LICENSE)
55
*/
@@ -50,13 +50,25 @@
5050
}
5151

5252
this.$element = $(element);
53-
this.$mirror = $('<div />').prependTo('body');
54-
this.$slider = $('<img />').prependTo(this.$mirror);
5553

5654
if (!this.imageSrc && this.$element.is('img')) {
5755
this.imageSrc = this.$element.attr('src');
5856
}
5957

58+
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
59+
if (this.iosFix && !this.$element.is('img')) {
60+
this.$element.css({
61+
backgroundImage: 'url(' + encodeURIComponent(this.imageSrc) + ')',
62+
backgroundSize: 'cover',
63+
backgroundPosition: 'center'
64+
});
65+
}
66+
return this;
67+
}
68+
69+
this.$mirror = $('<div />').prependTo('body');
70+
this.$slider = $('<img />').prependTo(this.$mirror);
71+
6072
this.$mirror.addClass('parallax-mirror').css({
6173
visibility: 'hidden',
6274
zIndex: this.zIndex,
@@ -94,6 +106,7 @@
94106
speed: 0.2,
95107
bleed: 0,
96108
zIndex: -100,
109+
iosFix: true,
97110

98111
refresh: function() {
99112
this.boxWidth = this.$element.width();

parallax.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)