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. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?2. java - spring boot 如何打包成asp.net core 那種獨立應用?3. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?4. datetime - Python如何獲取當前時間5. javascript - nginx反向代理靜態資源403錯誤?6. docker網絡端口映射,沒有方便點的操作方法么?7. 安全性測試 - nodejs中如何防mySQL注入8. javascript - 關于apply()與call()的問題9. docker start -a dockername 老是卡住,什么情況?10. python - 調用api輸出頁面,會有標簽出現,請問如何清掉?
