parallax_color_bars
Version:
parallax color bars
3 lines (2 loc) • 2.16 kB
JavaScript
var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"undefined"!=typeof exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){t.fn.parallaxColorBars=function(o){var e={init:function(o){var e=t.extend({duration:1.5,shift:10,top:50,left:50,width:10,height:20},o),i=0,r=0,n=0;t(window).on("scroll load",function(){i=t(window).scrollTop(),r=t(window).height(),n=i+r}),this.each(function(){var o=t(this),i=o.find(".color-bar"),s=o.outerWidth(),a=o.outerHeight();t(window).on("resize",function(){s=o.outerWidth(),a=o.outerHeight()}),i.each(function(){var o=t(this),i=o.outerHeight(),h=0,f=0,d=0,l=0,p=e.top,u=e.left,c=e.width,y=e.height,w=e.duration,b=e.shift,m=o.find(".color-bar-background"),g=o.data("parallax-color-bar");void 0!=g&&(g.hasOwnProperty("duration")&&(w=g.duration),g.hasOwnProperty("shift")&&(b=g.shift),g.hasOwnProperty("top")&&(p=g.top),g.hasOwnProperty("left")&&(u=g.left),g.hasOwnProperty("width")&&(c=g.width),g.hasOwnProperty("height")&&(y=g.height)),o.css({top:p+"%",left:u+"%",position:"absolute",overflow:"hidden",width:c+"%",height:y+"%"}),m.css({position:"absolute"}),t(window).bind("resizeEnd load",function(){m.css({width:s+"px",height:a+"px",left:-s/100*g.left+"px",top:-a/100*g.top+"px"}),d=o.offset(),h=d.top,f=h+r,l=f-h}),t(window).resize(function(){this.resizeTO&&clearTimeout(this.resizeTO),this.resizeTO=setTimeout(function(){t(this).trigger("resizeEnd")},500)}),t(window).on("scroll resize load",function(){if(n>h&&n<f+i){o.addClass("active");var t=n-d.top-.5*l,e=t/(l/100)*2,r=b/100*e;TweenLite.to(o,w,{y:r+"px"}),TweenLite.to(m,w,{y:-r+"px"})}else o.removeClass("active")})})})}};return e[o]?e[o].apply(this,Array.prototype.slice.call(arguments,1)):"object"!==(void 0===o?"undefined":_typeof(o))&&o?void t.error("There is no method with the name "+o+", for jQuery.parallaxColorBars"):e.init.apply(this,arguments)}});
//# sourceMappingURL=parallaxColorBars.min.js.map
;