function windetail(obj){ this.mobilefn = obj.mobilefn; this.ipadfn = obj.ipadfn; this.pcfn = obj.pcfn; this.changeuifn = obj.changeuifn; this.changesizefn = obj.changesizefn; this.limit = obj.limit || object.create(null); this.state = { uimode: undefined, isreadly: undefined, winheight: window.innerheight, winwidth: window.innerwidth } this.state.uimode = this.getuimode(); this.state.isreadly = this.isreadly(); this.ishide = false; // 初始化 this.install(true); // 绑定监听 this.onsize(); } // 获取ui模式 windetail.prototype.getuimode = function(winwidth){ var width = winwidth || this.state.winwidth; if (width > 1040){ return 'pc' ; } else if ( width > 450 && width <= 1040){ return 'ipad' ; } else { return 'mobile' ; } } // 是否满足限制 windetail.prototype.isreadly = function(){ var limitheight = this.limit[this.state.uimode]; if (!limitheight){ return true } else { if (this.state.winheight >= limitheight){ return true } else { return false } } } // 绑定监听 windetail.prototype.onsize = function(){ window.onresize = this.changesize.call(this); } windetail.prototype.changesize = function(){ var timer = null; var _this = this; return function(){ if (timer){ cleartimeout(timer); } timer = settimeout(_this.changesizecallback.bind(_this), 200); } } // 监听回调 windetail.prototype.changesizecallback = function(){ var winwidth = window.innerwidth; var winheight = window.innerheight; var newuimode = this.getuimode(winwidth); var flag = false; if ((this.state.uimode === newuimode) && (this.state.winheight === winheight)){ flag = false; } else { this.state = { uimode: newuimode, isreadly: undefined, winheight: winheight, winwidth: winwidth } this.state.isreadly = this.isreadly(); var uichangecb = this[newuimode + 'fn']; if (uichangecb && uichangecb instanceof function){ uichangecb(this.state); } flag = true; } this.install(flag); this.onvisible(this.state.isreadly); } // 初始化方法 windetail.prototype.install = function(uichangeflag){ // 各个终端方法 var terminalfn = this[this.state.uimode + 'fn']; if (uichangeflag && terminalfn && terminalfn instanceof function){ terminalfn(this.state); } if (uichangeflag && this.changeuifn && this.changeuifn instanceof function){ this.changeuifn(this.state); } if (this.changesizefn && this.changesizefn instanceof function){ this.changesizefn(this.state); } } windetail.prototype.onvisible = function(flag){ if (!flag){ this.onhide(); } else if (flag && this.ishide){ this.onshow(); }; } windetail.prototype.onshow = function(){ var pd = document.getelementbyid('preventtran'); pd.style.display = 'none'; this.ishide = false; } windetail.prototype.onhide = function(){ var pd = document.getelementbyid('preventtran'); if (!pd){ var imgdata = 'data:image/png;base64,ivborw0kggoaaaansuheugaaadwaaabacayaaadkutu1aaai9eleqvr4xu1cfxbcvru/5+z1n8gej2ahfqvuiigfbetyarvbbhadu2whvoyk3bx3k8kmcsyfpxzuf8ifojrqihyuxbl3vw6mkxbtinapg1colleunyij9qpgoe0vdujjle3tdnffo87j7gy26yz9h5tnst37x5tzzu/87rl777v3nnmr5rhfo9hlhbdrhrc3ambqafgbabfmyu8cwagahagavwdgjaxuo+vc6u7uxhkoh0/gyrgxic5jeovzdlg3t7fdczyhiogorhsl4xdrfihee/f4fb8aegnikdcs0fma8ixpmluc+ozwedcy0wh0jazp2wfgjwulmoje9corbrvcehccip4paoopvoqszdjp+7vdmcibnmzqvqxymycixwea4dehej2o+gleff/h/xfxftwef9mv/yoq7u/vb06n00ka+fypixweahgdaj4dgf9nmpmj4+pj77jca2vr0na4fc0araeao4lotyvh/22l1jfnjxakemluawn5jqb8ukx09hlrggvzb7hxunf1m4qqjxhrxlmi/0kpxz3kqwwnmeopfwiakrl0fwnan1lq51696ujoukkxsfewafw6k246nv45pdzms7vnfoiwlpiraphuceqbjupcyvnwv7x609nz+cfwomzl0xvn0d2qlokj0xpztzjxxyaghqmaec5c/aomaetisrivr55av1fxsivllhxexjvnu+qlyjtnz55nrtzffrowuj4dajukji4j4up4ph7mjyogytynipe70swidck+xymvcinfloolcdqaxavpgk9eu/qo40qtyxry6kbb3jcmpuqueujsikibepeqanbmsseypmn+1cuel8jsyh8aqh8bjiiomkb5ca/gs8l3dnae39jyejfjodxjxw8apnsn1mmiuqzp9njf9exymiw3efg6iskbtnn81iu4f/mbgqexojq6dga2a8anaec3sqmhvdhgwb+e/4mibxkwo5vkxzxmjj1pvf6drys8x8ipi+k3akcbilabprmtes5uw4yvwuyyrusxnjlzrtu1a1eg7vo1saaepavtzcxxfee4kk5u01adcdv7ez6w6hgej16vjmy9wtxs7fnakhvhscts1ntutfqicz5t2xubbyjo+7trbeciitkztobk8pdwf8rptcpt0dfxutgc/ioa8kdjg1uqhshhrg8t0bztp069kewmmwufpwgbhnetiv4gac5yiat8+stebdu+nzfi/gnqtxsjrfqbm5v/ioifkxc/9heq3gki+qhpmu9orrinp+cpiupdqn5wyk+fkau2y19f3ww5xo4eb/xkghyk9zteqiliudhq92kyirko41ynhmf0iwlzsygi6jdn88mkom2becmwhkteh7o1tusp8eh64wbqdgnfa4qbwcrchhyhxc/vioe9tjipou+te+bzqsz+wwbqj/c0kv2psnv5v0pyxpel+pauduytdulfamdd59kyvcdcipyihdjj2wx2zddq0n90xf+weilzrs7kc5pch2spwg4ilo3h4+ofoekppwaaf8/flnyc4f1kqdtl5ympjsfkfkqwlnvsha8rpw4ujdzt0/m6ed1uc4q56w8rp6ou4ohotu7u7tueem/ndyrqbkgzxywrdrlrbktsres9kdmmjgnp9mg7h494onz/90nnruw6lm1owerjidd1wvuiv2nl5wxg7/awpqqx+bf0bimkyd/s50yeiwi4trh4pntaolyimgfb3nmunhgquyy/tl6rrzuqxzljrfmf4l6wjerjiijxajxpyg8nim50izv5mabr+i1ccn+ft27bfojclpe7hi/eeei6le+6xgh+zzupu5vs909maesj0as1tepqsfpmcm0+7rlro7ztr0okeiemklrypllc7sr5dg4osf8tqtwzodjixwptswa4p6ulpywrsh5dxe/maxi1thkqbpchfjovsh0qrkadmelmstmstqdbgxsbf1w+vi6xoyoeogfzvrpc71ysy65aoqukuycctacxun49wgs9qkh9w5qr3rjly/vntu0jsvjsv147yferbm9vdy9btoxva28kovei6powzr3wqtop4ylo5bsb1wy6rm8uqhsx2t+tlhraiw+ecrugsqcrbwoao1xgk4t4vsatexfoaoiuf2a/sljktphkvmnjrkrpmqy5vdbrxqyfwux2z1ka4az0p/dzmgcwzztn424c8cijpdxd/mcc4zjblmt6wosnz4r1xb9zcmhbydkax+txmzpcz/xjprsxzwdqfx19s3k5hg8acrf5iiryozg4+koxw54jc+hyswphuh74epda25vsw13kziim6zqxy3oec20sluq1ex2mxjnhrpnsmlxr64lehk3thojfyjzkazup5e8aoljs/kdkqqe9gvvlmnon+cgs2dpzjunsmmnx4svrxdc7hba7i3r4hfiyuur3xuywrc/c/cbbobzm93rc5qcj6mwxsbgne/fu9fxhugovgo1e3tdqcaqrly78jyienu2z+ekn17x9ec4p6xcagjenay2idk5mtnyvtcynxhsxgyb3bcguehkrbywim7ft+4zeivgwh/u+ceu6/paq4ntlqf87ffr03ufl5xt7ey+1bxsfp4zsjoe4zqowzfh7a76ab8jdxv1xhukht2cy0qoo48gdo3bs9+ovyrh3akaces8r0edshm7e5ymcx8034fyw/jmaxamaxfnyehtetvfe83wl1f/cenfd3x2deojr+sdqpj1crkshjyymbg/6uwle2dampuylzlpzezvniyfi6ztazjoj8+0f54mdymazbx0/fnwyu2758uwtovdoi7ztr+wtrsjaw67eisfbtcazeefone+56bjzzairzhtmg8q7mba2tu8awbcrwktfnfx4ymjiowcohmgfjcv6lsa8zq8p5a0awjpzqiaoeteb/aigzvkhg9gp1a04yqaircinzc3n9yhil4honyeif4b/9/pf374np5k6au4if4njkt8eao355e5+nelyacjcbvj7wkmawlusv3k53l5eish/nrp2pzajnfmp9znfaaaaaelftksuqmcc'; pd = document.createelement('div'); pd.setattribute('id','preventtran'); pd.style.position = 'fixed'; pd.style.left = '0'; pd.style.top = '0'; pd.style.width = '100%'; pd.style.height = '100%'; pd.style.overflow = 'hidden'; pd.style.backgroundcolor = '#2e2e2e'; pd.style.textalign = 'center'; pd.style.zindex = '99999'; document.getelementsbytagname('body')[0].appendchild(pd); var img = document.createelement('img'); img.src = imgdata; pd.appendchild(img); img.style.margin = '60px auto 30px' var br = document.createelement('br'); var p = document.createelement('p'); p.style.width = '100%'; p.style.height = 'auto'; p.style.fontsize = '22px'; p.style.color = '#626262'; p.style.lineheight = '34px'; p.style.textalign = 'center'; p.innerhtml = '为了您的良好体验'; p.appendchild(br); p.innerhtml += '请将手机/平板竖屏操作'; p.appendchild(br); p.innerhtml += '或点击此处刷新'; p.addeventlistener('click', function(){ window.location.reload(); }) pd.appendchild(p); } else { pd.style.display = 'block'; } this.ishide = true; }