$.parallax = { instance : [] , id : 0 }; $.fn.parallax = function(options){ if(this.length > 1){ this.each(function(){ $(this).parallax(); }); return; } var left = parseint(this.css('left')) || 0; var top = parseint(this.css('top')) || 0; var right = parseint(this.css('right')) || 0; var bottom = parseint(this.css('bottom')) || 0; var def = { start : { left : left, top : top, opacity : 1, right : 0, bottom : 0 }, end : { left : left, top : top, opacity : 1, right : right, bottom : bottom }, speed : 400, easing : 'easeoutexpo' }; var opt = $.extend(true,def,options); if(opt.start.right){ opt.start.left = "auto"; opt.end.left = "auto"; } else{ opt.start.right = "auto"; opt.end.right = "auto"; } if(opt.start.bottom){ opt.start.top = "auto"; }else{ opt.start.bottom = "auto"; } var status = 0; var self = this; $.parallax.instance.push({ id : $.parallax.id++, dom : self, start : opt.start, end : opt.end, speed : opt.speed, easing : opt.easing, status : status }); }; $(function(){ // $('.indextit').parallax({start : {left:-10,opacity : 0},speed :2000}); // $('.indextit').parallax({start : {right:-200,opacity : 0},speed :2000}); // $('.indextit').parallax({start : {top:-20,opacity : 0},speed :1500}); // $('.indextit img').parallax({start : {right:-250,opacity : 0},speed :1500}); // $('.indexone .us2').parallax({start : {left:-200,opacity : 0},speed :2000}); // $('.indexone .us3').parallax({start : {right:-200,opacity : 0},speed :2000}); // $('.indexone .us4').parallax({start : {right:-200,opacity : 0},speed :2500}); $('.indexthree li').eq(0).parallax({start : {left:-250,opacity : 0},speed :1500}); $('.indexthree li').eq(1).parallax({start : {left:-250,opacity : 0},speed :1500}); $('.indexthree li').eq(2).parallax({start : {right:-250,opacity : 0},speed :1500}); $('.indexthree li').eq(3).parallax({start : {right:-250,opacity : 0},speed :1500}); $('.indextwo li').eq(0).parallax({start : {bottom:-150,opacity : 0},speed :2000}); $('.indextwo li').eq(1).parallax({start : {bottom:-150,opacity : 0},speed :2000}); $('.indextwo li').eq(2).parallax({start : {bottom:-150,opacity : 0},speed :2000}); $('.infourleft').parallax({start : {left:-250,opacity : 0},speed :2500}); $('.infourright').parallax({start : {right:-250,opacity : 0},speed :2500}); var winheight = $(window).height(); var inwindow = function(dom){ var d = dom.get(0); var p = d.getboundingclientrect(); return p.top < winheight/1.1; }; var init = function(){ for(var i = 0 ; i < $.parallax.instance.length; i++){ var d = $.parallax.instance[i]; if( d.status < 1){ d.dom.css(d.start); d.status = 1; } } }; var move = function(){ for(var i = 0 ; i < $.parallax.instance.length; i++){ var d = $.parallax.instance[i]; if(d.dom.length < 1) return; if( d.status > 0 && inwindow(d.dom)){ d.dom.animate(d.end,d.speed,d.easing); d.status = 0; } } }; init(); move(); $(window).scroll(function(event) { move(); }); });