Skip to content

Commit 253739c

Browse files
committed
update parallax.js to version 1.2, add documentation for androidFix, and genericise the mobile user agent message
1 parent e2ddf13 commit 253739c

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

index.html

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<script src="./js/bootstrap.min.js"></script>
1717
<script>
1818
$(function(){
19-
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
19+
if (navigator.userAgent.match(/(iPod|iPhone|iPad|Android)/)) {
2020
$('#ios-notice').removeClass('hidden');
2121
$('.parallax-container').height( $(window).height() * 0.5 | 0 );
2222
} else {
@@ -32,10 +32,10 @@
3232
<body>
3333
<section>
3434
<div class="container">
35-
<div id="ios-notice" class="alert alert-info hidden"><p><strong>Notice:</strong> Hello iOS user. Unfortunately, this parallax effect cannot be achieved on iOS devices, so all you will see on this demo page are static backgrounds. Please visit this page on a desktop browser to see its full effect.</p></div>
35+
<div id="ios-notice" class="alert alert-info hidden"><p><strong>Notice:</strong> Hello mobile user. Unfortunately, this parallax effect is not reliably achieved on mobile devices, so all you will see on this demo page are static backgrounds. Please visit this page on a desktop browser to see its full effect.</p></div>
3636
<h1>Simple Parallax Scrolling <small>parallax.js</small></h1>
3737
<p>Parallax.js is a dirt simple parallax scrolling effect inspired by <a href="http://spotify.com">Spotify.com</a> and implemented as a jQuery plugin.</p>
38-
<a href="https://github.com/pixelcog/parallax.js/archive/v1.1.zip" class="btn btn-default download-link">Download Parallax.js v1.1</a>
38+
<a href="https://github.com/pixelcog/parallax.js/archive/v1.2.zip" class="btn btn-default download-link">Download Parallax.js v1.2</a>
3939
<a href="https://github.com/pixelcog/parallax.js/" class="btn btn-default">View on GitHub</a>
4040
</div>
4141
</section>
@@ -158,6 +158,12 @@ <h2 id="options">Options</h2>
158158
<td>true</td>
159159
<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>
160160
</tr>
161+
<tr>
162+
<td>androidFix</td>
163+
<td>boolean</td>
164+
<td>true</td>
165+
<td>If true, this option will set the parallax image as a static, centered background image whenever it detects an Android user agent. Disable this if you wish to enable the parallax scrolling effect on Android devices.</td>
166+
</tr>
161167
</tbody>
162168
</table>
163169
</div>

js/parallax.js

100644100755
+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* parallax.js v1.1 (http://pixelcog.github.io/parallax.js/)
2+
* parallax.js v1.2 (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
*/
@@ -99,7 +99,18 @@
9999
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
100100
if (this.iosFix && !this.$element.is('img')) {
101101
this.$element.css({
102-
backgroundImage: 'url(' + encodeURIComponent(this.imageSrc) + ')',
102+
backgroundImage: 'url(' + this.imageSrc + ')',
103+
backgroundSize: 'cover',
104+
backgroundPosition: this.position
105+
});
106+
}
107+
return this;
108+
}
109+
110+
if (navigator.userAgent.match(/(Android)/)) {
111+
if (this.androidFix && !this.$element.is('img')) {
112+
this.$element.css({
113+
backgroundImage: 'url(' + this.imageSrc + ')',
103114
backgroundSize: 'cover',
104115
backgroundPosition: this.position
105116
});
@@ -148,7 +159,8 @@
148159
bleed: 0,
149160
zIndex: -100,
150161
iosFix: true,
151-
position: 'center',
162+
androidFix: true,
163+
position: 'center',
152164

153165
refresh: function() {
154166
this.boxWidth = this.$element.width();

js/parallax.min.js

100644100755
+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)