/*根据屏幕适配font-size*/ /*;(function (doc, win) { var docel = doc.documentelement, resizeevt = 'onorientationchange' in window ? 'onorientationchange' : 'resize', recalc = function () { var clientwidth = docel.clientwidth; if (!clientwidth) return; if(clientwidth>=750){ docel.style.fontsize = '100px';//屏幕大于750,font-size:100px; }else{ docel.style.fontsize = 100 * (clientwidth / 750) + 'px'; } }; if (!doc.addeventlistener) return; win.addeventlistener(resizeevt, recalc, false); doc.addeventlistener('domcontentloaded', recalc, false); })(document, window);*/ ;(function($, window, document,undefined) { var tfn = function($,doc) { this.header = $('header'), this.center = $('#wrapper'), this.footer = $('footer'), this.windowwidth = ('innerwidth' in window) ? window.innerwidth : document.documentelement.clientwidth,//屏幕宽度 this.windowheight = ('innerheight' in window) ? window.innerheight : document.documentelement.clientheight,//屏幕高度 this.ienum = parseint(navigator.appversion.split(";")[1].replace(/[ ]/g, "").replace("msie",""));//如果是ie浏览器,ie的版本数 this.isanimating = false,//判断动画是否进行中 this.anitime = 600, //动画时间 this.support = { animations : modernizr.cssanimations },//是否支持1,animations this.animendeventnames = { 'webkitanimation' : 'webkitanimationend', 'oanimation' : 'oanimationend', 'msanimation' : 'msanimationend', 'animation' : 'animationend' }, this.animendeventname = this.animendeventnames[ modernizr.prefixed( 'animation' ) ], this.onendanimation = function( el, callback ) {//动画所属元素,如果不支持animations回调函数。 var self = this; var onendcallbackfn = function( ev ) { if( self.support.animations ) { if( ev.target != this ) return; this.removeeventlistener( self.animendeventname, onendcallbackfn ); } if( callback && typeof callback === 'function' ) { callback.call(); } }; if( self.support.animations ) { el.addeventlistener( self.animendeventname, onendcallbackfn ); } else { onendcallbackfn(); } }, this.init(); /*var transendeventnames = { 'webkittransition' : 'webkittransitionend', 'moztransition' : 'transitionend', 'otransition' : 'otransitionend', 'mstransition' : 'mstransitionend', 'transition' : 'transitionend' }, this.transendeventname = transendeventnames[ modernizr.prefixed('transition') ]; //transition结束事件*/ } tfn.prototype = { //初始化 init : function() { if (!!window.activexobject || "activexobject" in window){$('body').addclass("ie");} if(this.ienum<9){ alert("您的浏览器版本过低,请下载ie9及以上版本");return false; }else if(this.ienum==9){ $('body').addclass("ie9"); }else if(this.ienum==10){ $('body').addclass("ie10"); }else if(this.ienum==11){ $('body').addclass("ie11"); } this.contentinit(); this.appnav(); this.downmove(); this.picmove(); this.piccut(); this.dialog(); this.scrolly(); $('.video-btn').on('click',function(){ var _src = $('.video-bj').attr('data-url'); $('#lunvideotan').find('source').attr('src',_src); console.log(_src); $('#lunvideotan')[0].load(); $('#lunvideotan')[0].play(); }); }, //内容层min-height contentinit:function(){ var self = this, minheight =self.windowheight - (self.header.height() + self.footer.height()); self.center.css('min-height',minheight+'px'); $('.picbox').each(function(index,e){ var wid=$(this).width(), hei=parseint(wid*($(this).attr('data-hei'))); $(this).css('height',hei+"px"); }); }, //页面切换(针对setinterval) visibilitychange:function ( gofn , backfn ) { var hiddenproperty = 'hidden' in document ? 'hidden' : 'webkithidden' in document ? 'webkithidden' : 'mozhidden' in document ? 'mozhidden' : null; var visibilitychangeevent = hiddenproperty.replace(/hidden/i, 'visibilitychange'); var onvisibilitychange = function(){ if (!document[hiddenproperty]) { backfn.call(); }else{ gofn.call(); } }; document.addeventlistener(visibilitychangeevent, onvisibilitychange); }, //手机菜单动画 appnav: function(){ var self = this, appnav = $('.app-nav'), getapp = appnav.find('.getappnav'), appul = appnav.find('ul'), appli = appul.find('li'), appulwid = appul.attr('data-width'), showani = appul.attr('data-effect'), hideani = appul.attr('data-hideani'); appul.css('width',(this.windowwidth*appulwid)+'px'); getapp.on('click',function(e){ if(self.isanimating) return false; self.isanimating = true; var isactive = $(this).hasclass('menuactive'); $(this).toggleclass('menuactive'); if(isactive){ appli.removeclass(showani).addclass(hideani); settimeout(function(){ appul.hide(); self.isanimating = false; },self.anitime); }else{ appli.removeclass(hideani).addclass(showani); appul.show(); settimeout(function(){ self.isanimating = false; },self.anitime); } }); }, //下拉动画 downmove:function(){ var self = this, downbox = $('.layout-down'), ishave = downbox.length<=0 ? true : false; if(ishave) return false; if(self.isanimating) return false; var isopen = function(){ console.log("下拉"); },//下拉时回调函数 isclose = function(){ console.log("未下拉"); };//未下拉时回调函数 var isactive = false; downbox.on('click',function(e){ self.isanimating = true; var isani = $(this).hasclass('father'), txtbox = $(this).find('.downtxt'), tdown = $(this).parents('.layout-down'), down = $(this).find('ul'), downli = down.find('li'), showani = down.attr('data-effect')||'fadeindown', hideani = down.attr('data-hideani')||'fadeoutdown'; isactive = $(this).attr('data-on')|| false; function downtoggle(e){ isactive = isactive==='true'?true:false; console.log(isactive); if( isactive ) { downli.removeclass(showani).addclass(hideani); self.onendanimation(downli[0],function(){ down.hide(); self.isanimating = false; }); // callback on close isclose( this ); } else { down.show(); downli.removeclass(hideani).addclass(showani); // callback on open isopen( this ); } isactive = !isactive; e.parents('.layout-down').attr('data-on',isactive); } downtoggle(down); downli.on('click',function(){ var txt = $(this).html(); txtbox.html(txt); }); }); }, //图片切割 piccut:function () { var self = this, tbox = $( '.piccut' ), tpic = tbox.find( 'img' ), src = tpic.attr('src'), rang = tbox.attr('data-hei'), boxmsg = {'width':tbox.width(),'height':parseint(tbox.width()*rang)}, rownum = tbox.attr( 'data-row' ), effect = tbox.attr( 'data-effect' )||'', delay = tbox.attr( 'data-delay' )||0, colnum = tbox.attr( 'data-col' ); var mwid = boxmsg.width/colnum, mhei = boxmsg.height/rownum; for(var i = 0;i'; tbox.append(str); } } }, //transform滚动惯性视差(背景滚动视差) scrolly:function () { var defaults = { wrapper: '#scrolly', parent_move : true,//容器跟随惯性滚动 targets : '.scrolly-el', bgparallax : false,//背景惯性滚动 wrapperspeed: 0.08, targetspeed: 0.02, targetpercentage: 0.1 }; var requestanimationframe = window.requestanimationframe || window.mozrequestanimationframe || window.webkitrequestanimationframe || window.msrequestanimationframe; window.requestanimationframe = requestanimationframe; var cancelanimationframe = window.cancelanimationframe || window.mozcancelanimationframe; var extend = function () { // variables var extended = {}; var deep = false; var i = 0; var length = arguments.length; // merge the object into the extended object var merge = function (obj) { for (var prop in obj) { if (obj.hasownproperty(prop)) { extended[prop] = obj[prop]; } } }; // loop through each object and conduct a merge for ( ; i < length; i++ ) { var obj = arguments[i]; merge(obj); } return extended; }; var scrolly = function(){ this.targets = []; this.targetslength = 0; this.wrapper = ''; this.windowheight = 0; this.wapperoffset = 0; }; scrolly.prototype = { isanimate: false, isresize : false, scrollid: "", resizeid: "", init : function(options){ this.settings = extend(defaults, options || {}); this.wrapper = document.queryselector(this.settings.wrapper); if(this.wrapper==="undefined"){ return false; } this.targets = document.queryselectorall(this.settings.targets); document.body.style.height = this.wrapper.clientheight + 'px'; this.windowheight = window.clientheight; this.attachevent(); this.apply(this.targets,this.wrapper); this.animate(); this.resize(); }, apply : function(targets,wrapper){ if(this.settings.parent_move){ this.wrapperinit(); } this.targetslength = targets.length; for (var i = 0; i < this.targetslength; i++) { var attr = { offset : targets[i].getattribute('data-offset'), speedx : targets[i].getattribute('data-speed-x'), speedy : targets[i].getattribute('data-speed-y'), percentage : targets[i].getattribute('data-percentage'), horizontal : targets[i].getattribute('data-v') }; this.targetsinit(targets[i],attr); } }, wrapperinit: function(){ this.wrapper.style.width = '100%'; this.wrapper.style.position = 'fixed'; }, targetsinit: function(elm,attr){ this.targets.push({ elm : elm, offset : attr.offset ? attr.offset : 0, offsettop : $(elm).offset().top, hei : $(elm).height(), horizontal : attr.horizontal ? attr.horizontal : 0, top : 0, left : 0, speedx : attr.speedx ? attr.speedx : 1, speedy : attr.speedy ? attr.speedy : 1, percentage :attr.percentage ? attr.percentage : 0 }); }, scroll : function(){ var scrolltoptmp = document.documentelement.scrolltop || document.body.scrolltop; this.scrolltop = document.documentelement.scrolltop || document.body.scrolltop; var offsetbottom = this.scrolltop + this.windowheight; if(this.settings.parent_move){ this.wrapperupdate(this.scrolltop); } for (var i = 0; i < this.targets.length; i++) { this.targetsupdate(this.targets[i]); } }, animate : function(){ this.scroll(); this.scrollid = requestanimationframe(this.animate.bind(this)); }, wrapperupdate : function(){ this.wapperoffset += (this.scrolltop - this.wapperoffset) * this.settings.wrapperspeed; this.wrapper.style.transform = 'translate3d(' + 0 + ',' + math.round(-this.wapperoffset* 100) / 100 + 'px ,' + 0 + ')'; }, targetsupdate : function(target){ var wh = $(window).height(); target.offsettop = $(target.elm).offset().top; target.top += ((this.scrolltop - target.offsettop + (wh-target.hei)/2) * number(this.settings.targetspeed) * number(target.speedy) - target.top) * this.settings.targetpercentage; target.left += ((this.scrolltop - target.offsettop + (wh-target.hei)/2) * number(this.settings.targetspeed) * number(target.speedx) - target.left) * this.settings.targetpercentage; var targetoffsettop = ( parseint(target.percentage) - target.top - parseint(target.offset) ); var offsety = math.round(targetoffsettop * -100) / 100; var offsetx = 0; if(target.horizontal){ var targetoffsetleft = ( parseint(target.percentage) - target.left - parseint(target.offset) ); offsetx = math.round(targetoffsetleft * -100) / 100; } if(this.settings.bgparallax){ if(target.horizontal){ $(target.elm).css({backgroundposition: offsetx +'px 50%'}); }else{ $(target.elm).css({backgroundposition: '50% ' + offsety + 'px'}); } }else{ target.elm.style.transform = 'translate3d(' + offsetx + 'px ,' + offsety + 'px ,' + 0 +')'; } }, resize: function(){ var self = this; self.windowheight = (window.innerheight || document.documentelement.clientheight || 0); if( parseint(self.wrapper.clientheight) != parseint(document.body.style.height)){ document.body.style.height = self.wrapper.clientheight + 'px'; } self.resizeid = requestanimationframe(self.resize.bind(self)); }, attachevent : function(){ var self = this; window.addeventlistener('resize',(function(){ if(!self.isresize){ cancelanimationframe(self.resizeid); cancelanimationframe(self.scrollid); self.isresize = true; settimeout((function(){ self.isresize = false; self.resizeid = requestanimationframe(self.resize.bind(self)); self.scrollid = requestanimationframe(self.animate.bind(self)); }),200); } })); } }; window.scrolly = new scrolly(); return scrolly; }, //单张图片切换动画(.tpage,.movenext,.moveprev); picmove:function(){ var self = this, picbox = $('.component'), ishave = picbox.length<=0 ? true : false; if(ishave) return false; var animendeventnames = { 'webkitanimation' : 'webkitanimationend', 'oanimation' : 'oanimationend', 'msanimation' : 'msanimationend', 'animation' : 'animationend' }, // animation end event name animendeventname = animendeventnames[ modernizr.prefixed( 'animation' ) ], component = null, items = null, current = 0,//当前页数 itemscount = null, navnext = document.queryselectorall( '.movenext' ), navprev = document.queryselectorall( '.moveprev' ), tpage = null, pagechange = document.queryselectorall( '.pagechange' ),//可选择页数 tpagechange = null, itemtxt = null,//轮播文字 loop = null, looptime = 6000;//轮播间隔时间 function reinit(_this,dir) { component = _this.parents( '.component' )[0],//容器 items = component.queryselector( 'ul.itemwrap' ).children,//图片项 itemscount = items.length, tpage = $(component.queryselector( '.tpage' )), current = parseint(tpage.attr( 'data-num' )), tpagechange= component.queryselectorall( '[data-change]' ); itemtxt = component.queryselectorall( '[data-txt]'); if(dir === 'num'){ var tnum = _this.attr('data-change'); } navigate( dir , tnum); } function goloop() { var _this = $('[data-loop]'); if(_this.length>0){ loop=setinterval(function () { for(var i =0;i<_this.length;i++){ reinit($(_this[i]),'next'); } },looptime); } } function navigate( dir , num) { if( self.isanimating) return false; self.isanimating = true; clearinterval(loop); var cntanims = 0; var currentitem = items[ current ]; var currenttxt = $(itemtxt).eq(current); if( dir === 'next' ) { current = current < itemscount - 1 ? current + 1 : 0; } else if( dir === 'prev' ) { current = current > 0 ? current - 1 : itemscount - 1; } else if( dir === 'num'){ current = parseint(num); } tpage.html('0'+(current+1)).attr('data-num',current); $(tpagechange).eq(current).addclass('on').siblings().removeclass('on'); var nextitem = items[ current ]; var nexttxt = $(itemtxt).eq(current); var onendanimationcurrentitem = function() { this.removeeventlistener( animendeventname, onendanimationcurrentitem ); classie.removeclass( this, 'current' ); currenttxt.removeclass('on txthide'); classie.removeclass( this, dir === 'next' ? 'navoutnext' : 'navoutprev' ); ++cntanims; if( cntanims === 2 ) { self.isanimating = false; goloop(); } } var onendanimationnextitem = function() { this.removeeventlistener( animendeventname, onendanimationnextitem ); classie.addclass( this, 'current' ); nexttxt.addclass('on').removeclass('txtshow'); classie.removeclass( this, dir === 'next' ? 'navinnext' : 'navinprev' ); ++cntanims; if( cntanims === 2 ) { self.isanimating = false; goloop(); } } if( self.support.animations ) { currentitem.addeventlistener( animendeventname, onendanimationcurrentitem ); nextitem.addeventlistener( animendeventname, onendanimationnextitem ); classie.addclass( currentitem, dir === 'next' ? 'navoutnext' : 'navoutprev' ); classie.addclass( nextitem, dir === 'next' ? 'navinnext' : 'navinprev' ); currenttxt.addclass('txthide'); nexttxt.addclass('txtshow'); } else { console.log('不支持css3 animated'); $(currentitem).hide(); $(nextitem).fadein(200); settimeout(function(){ classie.removeclass( currentitem, 'current' ); classie.addclass( nextitem, 'current' ); self.isanimating = false; },200) } } (function(){ for(var i=0;i