css3 - 怎么判斷瀏覽器是否支持translate3d
問題描述
transform之類的可以for in檢測出來,但是translate3d要怎么檢測呢?
問題解答
回答1:function has3d() { if (!window.getComputedStyle) {return false; } var el = document.createElement(’p’), has3d,transforms = { ’webkitTransform’:’-webkit-transform’, ’OTransform’:’-o-transform’, ’msTransform’:’-ms-transform’, ’MozTransform’:’-moz-transform’, ’transform’:’transform’}; // Add it to the body to get the computed style. document.body.insertBefore(el, null); for (var t in transforms) {if (el.style[t] !== undefined) { el.style[t] = 'translate3d(1px,1px,1px)'; has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);} } document.body.removeChild(el); return (has3d !== undefined && has3d.length > 0 && has3d !== 'none');}要做到各種瀏覽器兼容,你自己要去測試一下。
相關文章:
1. css - 如何把一個視圖放在左浮動定位的視圖的上面?2. javascript - axios請求回來的數據組件無法進行綁定渲染3. php多任務倒計時求助4. python的正則怎么同時匹配兩個不同結果?5. javascript - vue中怎么使用原生js插件6. javascript - 請問下面代碼中的...是擴展運算符還是操作運算符?這樣寫是什么意思?7. javascript - 小demo:請教怎么做出類似于水滴不斷擴張的效果?8. css - 子元素跑到父元素外面9. MySQL的聯合查詢[union]有什么實際的用處10. javascript - jquery怎么讓a標簽跳轉后保持tab的樣式
