$.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(){ if ($(window).width() > 1023){ $('.iproduct-channel li').eq(0).parallax({start : {left:-350,opacity : 0},speed :1500}); $('.iproduct-channel li').eq(1).parallax({start : {bottom:-150,opacity : 0},speed :2000}); $('.iproduct-channel li').eq(2).parallax({start : {right:-350,opacity : 0},speed :1500}); $('.iabout-us .m-ichl-title').parallax({start : {bottom:-150,opacity : 0},speed :2000}); $('.iabout-us .content').parallax({start : {bottom:-150,opacity : 0},speed :2000}); $('.iabout-us .more').parallax({start : {bottom:-150,opacity : 0},speed :2000}); $('.iabout-icons li').eq(0).parallax({start : {left:-350,opacity : 0},speed :1500}); $('.iabout-icons li').eq(1).parallax({start : {left:-350,opacity : 0},speed :2000}); $('.iabout-icons li').eq(2).parallax({start : {right:-350,opacity : 0},speed :1500}); $('.iabout-icons li').eq(3).parallax({start : {right:-350,opacity : 0},speed :1500}); $('.iabout-icons li').eq(4).parallax({start : {right:-350,opacity : 0},speed :2000}); $('.inews-list').parallax({start : {left:-350,opacity : 0},speed :2000}); $('.inews-pre').parallax({start : {right:-350,opacity : 0},speed :1500}); $('.full-inews .m-ichl-title').parallax({start : {bottom:-150,opacity : 0},speed :2000}); } 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(); }); });