Created
April 22, 2014 00:28
-
-
Save cirocosta/11161328 to your computer and use it in GitHub Desktop.
A simple parallax from the source of together js.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THE FOLLOWING CODE IS NOT MINE, WILL DO SOMETHING WITH IT LATER. CREDITS TO TOGETHERJS | |
$(document).ready(function(){ | |
// detect a mobile device | |
var isMobile = { | |
Android: function() { | |
return navigator.userAgent.match(/Android/i); | |
}, | |
BlackBerry: function() { | |
return navigator.userAgent.match(/BlackBerry/i); | |
}, | |
iOS: function() { | |
return navigator.userAgent.match(/iPhone|iPad|iPod/i); | |
}, | |
Opera: function() { | |
return navigator.userAgent.match(/Opera Mini/i); | |
}, | |
Windows: function() { | |
return navigator.userAgent.match(/IEMobile/i); | |
}, | |
any: function() { | |
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); | |
} | |
}; | |
// Cache the Window object | |
$window = $(window); | |
$('section[data-type="background"]').each(function(){ | |
var $bgobj = $(this); // assigning the object | |
$(window).scroll(function() { | |
// Scroll the background at var speed | |
// the yPos is a negative value because we're scrolling it UP! | |
var yPos = -($window.scrollTop() / $bgobj.data('speed')); | |
// Put together our final background position | |
var coords = '50% '+ yPos + 'px'; | |
if (isMobile.any()) { | |
//remove parallax | |
var coords = ''; | |
} | |
// Move the background | |
$bgobj.css({ backgroundPosition: coords }); | |
}); // window scroll Ends | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment