diff --git a/parallax/js/picasso-dev.js b/parallax/js/picasso-dev.js new file mode 100644 index 0000000..3dd82e7 --- /dev/null +++ b/parallax/js/picasso-dev.js @@ -0,0 +1,266 @@ +/*! Parallax functions +============================================================== +@name picasso-dev.js +@author Dave Gamache (@dhg) +@comments Christophe Zlobinski-Furmaniak (christophe.zf@gmail.com or @t1wk) +@version ? +@date 05/17/2014 +@category Animation scripts +@license ? + +@based-on: Dave Gamache Parallax (https://medium.com/@dhg/82ced812e61c) +@based-url: http://davegamache.com/parallax/ +============================================================== +*/ + +(function() { + $(function() { + + /* Globals + -------------------------------------------------- */ + // These CSS3 properties are known to be safe + var PROPERTIES = ['translateX', 'translateY', 'opacity', 'rotate', 'scale'], + + // Default values + $window = $(window), + $body = $('body'), + wrappers = [], + currentWrapper = null, + scrollTimeoutID = 0, + bodyHeight = 0, + windowHeight = 0, + windowWidth = 0, + prevKeyframesDurations = 0, + scrollTop = 0, + relativeScrollTop = 0, + currentKeyframe = 0, + + // Parallax animations are constructed as an object + keyframes = [ + { + + /* Parameters + // ---------------------------------------------------------------------- // + 'wrapper' : '#element_id', // Animation container + 'duration' : '100%', // Duration of the animation + 'animations' : [ + { + 'selector' : '.name', // Name of the selector + 'translateX' : 30, // (Integer, px) Translation on X Axis + 'translateY' : -140, // (Integer, px) Translation on Y Axis + 'opacity' : 0 // (Integer) Opacity + 'scale' : 1.2 // (Integer/floating, ratio) Scale (here 120 %) + 'rotate' : 90 // (Integer, degrees) Rotation + } , { + 'selector' : '.second_element_to_animate', + 'translateX' : '5%', // (String, %) Translation on X Axis + 'translateY' : '7%', // (String, %) Translation on Y Axis + 'scale' : [1, 2] // [From, to] + 'opacity' : [0, 1.75] // hack to accelerate opacity speed + } + ] + } */ + + 'wrapper' : '', + 'duration' : '100%', + 'animations' : [ + { + 'selector' : '', + 'translateY' : '', + 'opacity' : [0, 1.75] // hack to accelerate opacity speed + } + ] + } + ] + + /* Construction + -------------------------------------------------- */ + init = function() { + scrollIntervalID = setInterval(updatePage, 10); // Prevent crazy performance hiccups + setupValues(); + $window.resize(throwError) + if(isTouchDevice) { + $window.resize(throwError) + } + } + + setupValues = function() { + scrollTop = $window.scrollTop(); + windowHeight = $window.height(); + windowWidth = $window.width(); + convertAllPropsToPx(); + buildPage(); + } + + buildPage = function() { + var i, j, k; + for(i=0;i 0 && scrollTop <= (bodyHeight - windowHeight)) { + animateElements(); + setKeyframe(); + } + }); + } + + setScrollTops = function() { + scrollTop = $window.scrollTop(); + relativeScrollTop = scrollTop - prevKeyframesDurations; + } + + animateElements = function() { + var animation, translateY, translateX, scale, rotate, opacity; + for(var i=0;i (keyframes[currentKeyframe].duration + prevKeyframesDurations)) { + prevKeyframesDurations += keyframes[currentKeyframe].duration; + currentKeyframe++; + showCurrentWrappers(); + } else if(scrollTop < prevKeyframesDurations) { + currentKeyframe--; + prevKeyframesDurations -= keyframes[currentKeyframe].duration; + showCurrentWrappers(); + } + } + + showCurrentWrappers = function() { + var i; + if(keyframes[currentKeyframe].wrapper != currentWrapper) { + $(currentWrapper).hide(); + $(keyframes[currentKeyframe].wrapper).show(); + currentWrapper = keyframes[currentKeyframe].wrapper; + } + } + + /* Helpers + -------------------------------------------------- */ + + convertPercentToPx = function(value, axis) { + if(typeof value === "string" && value.match(/%/g)) { + if(axis === 'y') value = (parseFloat(value) / 100) * windowHeight; + if(axis === 'x') value = (parseFloat(value) / 100) * windowWidth; + } + return value; + } + + throwError = function() { + $body.addClass('page-error') + } + + isTouchDevice = function() { + return 'ontouchstart' in window // works on most browsers + || 'onmsgesturechange' in window; // works on ie10 + } + + init(); + + }) +}).call(this); \ No newline at end of file