/*根据屏幕适配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'; // } // }; // settimeout(function(){console.log($('header').height());},1); // if (!doc.addeventlistener) return; // win.addeventlistener(resizeevt, recalc, false); // doc.addeventlistener('domcontentloaded', recalc, false); // })(document, window); /* author : zhcool; date : 2018/7/13; version : v0.0.9; */ ;(function($, window, document,undefined) { "use strict"; var tfn = function() { this.header = $('header'), this.center = $('#wrapper'), this.footer = $('footer'), this.author = 'zhcool', this.windowwidth = ('innerwidth' in window) ? window.innerwidth : document.documentelement.clientwidth,//屏幕宽度 this.windowheight = ('innerheight' in window) ? window.innerheight : document.documentelement.clientheight,//屏幕高度 this.ienum = null;//如果是ie浏览器,ie的版本数 this.wx = false; this.isanimating = false,//判断轮播动画是否进行中 this.isanimating1 = false,//判断下拉动画是否进行中 this.anitime = 600, //动画时间 this.rag = window.requestanimationframe, this.ispc = null,//是否为pc端 this.rownode = [],//页面块节点存储 this.appdirection = null;//手机端触摸滑动方向 }; tfn.prototype = { //初始化 init : function() { var self = this; var ua = navigator.useragent.tolowercase(); if(ua.match(/micromessenger/i)=="micromessenger") { self.wx = true; $('body').addclass("iswx"); } else { self.wx = false; $('body').addclass("notwx"); } if (!!window.activexobject || "activexobject" in window){ $('body').addclass("ie"); this.ienum = parseint(navigator.appversion.split(";")[1].replace(/[ ]/g, "").replace("msie","")); 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"); } }else{ this.scrolly(); } }, //transform滚动惯性视差(背景滚动视差) scrolly:function () { var self = this; 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); } })); } }; if(!self.wx){ window.scrolly = new scrolly(); return scrolly; } } }; window._base = new tfn(); })(jquery, window, document); _base.init();