Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. function getStyle(dom, key) {
  2. let style
  3. if (window.getComputedStyle) {
  4. style = window.getComputedStyle(dom, null) // 非IE
  5. } else {
  6. style = dom.currentStyle // IE
  7. }
  8.  
  9. return style[key]
  10. }
  11.  
  12.  
  13. function isSupportCalc() {
  14. let oDiv = document.createElement("div");
  15. oDiv.style.width = 'calc((100vw / 750) * 100)'
  16.  
  17. document.body.appendChild(oDiv)
  18. let width = getStyle(oDiv, 'width')
  19. oDiv.remove()
  20.  
  21. let diff = 0.5
  22.  
  23. width = parseFloat(width)
  24. let calcWidth = window.screen.availWidth / 750 * 100
  25.  
  26. return width && Math.abs(calcWidth - width) < diff
  27. }
Add Comment
Please, Sign In to add comment