// javascript document var data={//全局变量 _vw:$(window).width(), _vh:$(window).height(), tpage:0, isani:false, _home:$('#page') }; var init=function(){ }; $(document).ready(function(){ new alan.scrollanimate(); init(); var home_next = function(){ if( data.isani) return false; data.isani = true; var items = document.queryselectorall('.row'), itemscount = items.length; if(data.tpage==(itemscount-1)){ $('footer').addclass('active'); data.tpage = (-1); settimeout(function () { data.isani = false; },800); }else if(data.tpage==(-1)){ settimeout(function () { data.isani = false; },800); } else{ _navigate( 'next' ,items,itemscount); } }; var home_prev =function(){ if( data.isani) return false; data.isani = true; var items = document.queryselectorall('.row'), itemscount = items.length; if(data.tpage>0){ _navigate( 'prev' ,items,itemscount); }else{ settimeout(function () { data.isani = false; },800); } if(data.tpage==(-1)){ $('footer').removeclass('active'); data.tpage = (itemscount-1); settimeout(function () { data.isani = false; },800); } }; if(data._home.length>0){ var _b = $('#page'); if(window.innerwidth>800){ stop(); _b.mousewheel(function(event) { if(event.deltay == -1){ home_next(); } else if(event.deltay == 1){ home_prev(); } }); } homefn.picmove();//引用首页函数1 homefn.fn2();//引用首页函数2 homefn.dis(); homefn.fn3(); homefn.play(); } }); var homefn = { picmove:function () { var box = $('.loop'); var tfn=function (opts) { this.parent = opts.parent; this.pic = opts.photo; this.isanimating = false; this.current = 0; this.timer = null; this.loop = false; this.items = this.parent.queryselector( '.itemwrap' ).children; this.itemscount = this.items.length; this.prev = this.parent.queryselector('.prev'); this.next = this.parent.queryselector('.next'); }; tfn.prototype={ init:function () { var self = this; // this.next.addeventlistener( 'click', function( ev ) { ev.preventdefault(); self.navigate( 'next' ); } ); // this.prev.addeventlistener( 'click', function( ev ) { ev.preventdefault(); self.navigate( 'prev' ); } ); this.pic.on('click',function () { self.navigate('num',$(this) ); }); self.goloop(); }, navigate:function (dir,el) { var self = this; cleartimeout(self.timer); if( self.isanimating) return false; self.isanimating = true; var cntanims = 0; var currentitem = self.items[ self.current ]; if( dir === 'next' ) { self.current = self.current < self.itemscount - 1 ? self.current + 1 : 0; } else if( dir === 'prev' ) { self.current = self.current > 0 ? self.current - 1 : self.itemscount - 1; } else if( dir === 'num' ) { self.current = el.index(); } var nextitem = self.items[ self.current ]; _on(self.pic.eq(self.current)); function a() { classie.removeclass( currentitem, 'on' ); classie.removeclass( currentitem, dir === 'prev' ? 'navoutprev' : 'navoutnext' ); ++cntanims; if( cntanims === 2 ) { settimeout(function () { self.isanimating = false; },200); } } function b() { classie.addclass( nextitem, 'on' ); classie.removeclass( nextitem, dir === 'prev' ? 'navinprev' : 'navinnext' ); ++cntanims; if( cntanims === 2 ) { settimeout(function () { self.isanimating = false; self.goloop(); },200); } } classie.addclass( currentitem, dir === 'prev' ? 'navoutprev' : 'navoutnext' ); classie.addclass( nextitem, dir === 'prev' ? 'navinprev' : 'navinnext' ); settimeout(function () { a(); b(); },1500); }, goloop:function () { var self = this; self.timer=settimeout(function () { self.loop = self.parent.getattribute('data-loop') == 'true' ? true :false; if(self.loop){ self.navigate( 'next' ); }else{ self.goloop(); } },3000); } }; box.each(function () { var _this = $(this)[0]; var pic = $(this).find('.pager').find('li'); new tfn({ parent:_this, photo:pic }).init(); }); }, fn2:function () { var c = document.getelementbyid('line'); var dx = c.getcontext('2d'); var w = c.width = window.innerwidth; var h = c.height = window.innerheight; var draw = function(a, b, t) { dx.linewidth = 0.8; dx.fillstyle = 'rgba(165, 195, 210, 1)'; dx.fillrect(0, 0, w, h); dx.clearrect(0, 0, w, h); for (var i = -60; i < 60; i += 1) { dx.strokestyle = 'rgba(165, 195, 210, 0.3)'; dx.beginpath(); dx.moveto(0, h / 2); for (var j = 0; j < w; j += 10) { dx.lineto(10 * math.sin(i / 10) + j + 0.008 * j * j, math.floor(h / 2 + j / 2 * math.sin(j / 50 - t / 50 - i / 118) + (i * 0.9) * math.sin(j / 25 - (i + t) / 65))); }; dx.stroke(); } }; var t = 0; window.addeventlistener('resize', function() { c.width = w = window.innerwidth; c.height = h = window.innerheight; dx.fillstyle = 'hsla(277, 95%, 55%, 1)'; }, false); var run = function() { window.requestanimationframe(run); t += 1; draw(33, 52 * math.sin(t / 2400), t); }; run(); }, dis:function () { var box = $('#r5'), _pic = box.find('.photo'), _btn = box.find('.pager').find('li'), _msg = box.find('.items').find('li'); if(window.innerwidth<800){ _pic = box.find('.photo_app'); } _btn.on('click', function () { var _this = $(this), _n = _this.index(); _on(_this); _on(_pic.eq(_n)); _on(_msg.eq(_n)); }); }, fn3:function () { var _box = $('#fn3'), _fn4 = $('#fn4'), _h = $('._href'), _go = _box.find('.g-down'); _go.on('click',function () { var _this = $(this), _num = _this.attr('data-num'), _other = _this.parents('li').siblings().find('p'), _p = _this.next(); _on(_this.parents('li')); _p.slidetoggle();_other.slideup(); _fn4.find('img').eq(_num).addclass('on').siblings().removeclass('on'); }); _h.find('a').on('mouseenter',function () { var n = $(this).index(); _on(_fn4.find('img').eq(n)); }); }, play:function () { var _btn = $('.play'); var _pop = $('#pop'), _close = $('._close'), _v = _pop.find('.media'); _btn.on('click',function () { var _this = $(this), _src = _this.attr('data-src'); _pop.addclass('on'); _v.attr('src',_src); _v[0].load(); }); _close.on('click',function () { $(this).parents('#pop').removeclass('on'); _v.attr('src',''); }); } }; function _on(el) { el.addclass('on').siblings().removeclass('on'); } function _navigate( dir ,items,itemscount) { data.isani = true; var cntanims = 0; var currentitem = items[ data.tpage ]; if( dir === 'next' ) { data.tpage = data.tpage < itemscount - 1 ? data.tpage + 1 : 0; } else if( dir === 'prev' ) { data.tpage = data.tpage > 0 ? data.tpage - 1 : itemscount - 1; } else if( dir === 'num' ){ data.tpage = data.choosepage; } var nextitem = items[ data.tpage ]; if(data.tpage==2){$('header').addclass('on')}else{$('header').removeclass('on')}; function a() { classie.removeclass( currentitem, 'on' ); classie.removeclass( currentitem, dir === 'prev' ? 'navoutprev' : 'navoutnext' ); ++cntanims; if( cntanims === 2 ) { settimeout(function () { data.isani = false; },100); } } function b() { classie.addclass( nextitem, 'on' ); classie.removeclass( nextitem, dir === 'prev' ? 'navinprev' : 'navinnext' ); ++cntanims; if( cntanims === 2 ) { settimeout(function () { data.isani = false; },100); } } classie.addclass( currentitem, dir === 'prev' ? 'navoutprev' : 'navoutnext' ); classie.addclass( nextitem, dir === 'prev' ? 'navinprev' : 'navinnext' ); settimeout(function () { a(); b(); },800); } var mo=function(e){e.preventdefault();}; function stop(){ document.body.style.overflow='hidden'; document.addeventlistener("touchmove",mo,false);//禁止页面滑动 } function move(){ document.body.style.overflow='';//出现滚动条 document.removeeventlistener("touchmove",mo,false); }