vminunit.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. /*!
  2. {
  3. "name": "CSS vmin unit",
  4. "property": "cssvminunit",
  5. "caniuse": "viewport-units",
  6. "tags": ["css"],
  7. "builderAliases": ["css_vminunit"],
  8. "notes": [{
  9. "name": "Related Modernizr Issue",
  10. "href": "https://github.com/Modernizr/Modernizr/issues/572"
  11. },{
  12. "name": "JSFiddle Example",
  13. "href": "https://jsfiddle.net/glsee/JRmdq/8/"
  14. }]
  15. }
  16. !*/
  17. define(['Modernizr', 'docElement', 'testStyles', 'roundedEquals', 'computedStyle'], function(Modernizr, docElement, testStyles, roundedEquals, computedStyle) {
  18. testStyles('#modernizr1{width: 50vm;width:50vmin}#modernizr2{width:50px;height:50px;overflow:scroll}#modernizr3{position:fixed;top:0;left:0;bottom:0;right:0}', function(node) {
  19. var elem = node.childNodes[2];
  20. var scroller = node.childNodes[1];
  21. var fullSizeElem = node.childNodes[0];
  22. var scrollbarWidth = parseInt((scroller.offsetWidth - scroller.clientWidth) / 2, 10);
  23. var one_vw = fullSizeElem.clientWidth / 100;
  24. var one_vh = fullSizeElem.clientHeight / 100;
  25. var expectedWidth = parseInt(Math.min(one_vw, one_vh) * 50, 10);
  26. var compWidth = parseInt(computedStyle(elem, null, 'width'), 10);
  27. Modernizr.addTest('cssvminunit', roundedEquals(expectedWidth, compWidth) || roundedEquals(expectedWidth, compWidth - scrollbarWidth));
  28. }, 3);
  29. });