第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

js的html5方法有些有前綴,如何寫兼容的代碼?

js的html5方法有些有前綴,如何寫兼容的代碼?

哆啦的時光機 2019-04-08 09:21:57
比如animationend就有幾種:webkitAnimationEnd/oAnimationEnd/MSAnimationEnd/animationend,這樣應(yīng)該怎么寫兼容的代碼?或者是優(yōu)雅降級的代碼比如requestAnimationFrame和cancelRequestAnimFrame可以這樣寫,但是animationend這樣寫不行...window.requestAnimationFrame=(function(){returnwindow.requestAnimationFrame||//Chromiumwindow.webkitRequestAnimationFrame||//Webkitwindow.mozRequestAnimationFrame||//MozillaGekowindow.oRequestAnimationFrame||//OperaPrestowindow.msRequestAnimationFrame||//IETrident?function(callback,element){//Fallbackfunctionconsole.log("Fallback");returnwindow.setTimeout(callback,1000/30);}})();window.cancelRequestAnimFrame=(function(){returnwindow.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelRequestAnimationFrame||window.oCancelRequestAnimationFrame||window.msCancelRequestAnimationFrame||clearTimeout})();根據(jù)dolymood的方法,加上我wiki了一下,整理出一個可以判斷瀏覽器前綴的方法,當然,使用limichange提到的Modernizr.prefixed也很方便。varanimEndEventNames={'webkit':'webkitAnimationEnd','o':'oAnimationEnd','ms':'MSAnimationEnd','animation':'animationend'},animEndEventName=animEndEventNames[prefix().lowercase]||animEndEventNames['animation'];functionprefix(){varstyles=getCompStyle(document.documentElement),pre=(Array.prototype.slice.call(styles).join('').match(/-(moz|webkit|ms)-/)||['','o'])[1],dom=('WebKit|Moz|MS|O').match(newRegExp('('+pre+')','i'))[1];return{dom:dom,lowercase:pre,css:'-'+pre+'-',js:pre[0].toUpperCase()+pre.substr(1)};};functiongetCompStyle(elem,classes){return(window.getComputedStyle?window.getComputedStyle(elem,classes||null):elem.currentStyle)||null;}
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 306 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號