123456789101112131415161718192021222324252627282930 |
- export function flexible(options) {
- const docEl = document.documentElement;
- const dpr = window.devicePixelRatio || 1;
- function setRemUnit() {
- let cwidth = docEl.clientWidth;
- if (options.minWidth) {
- cwidth = Math.max(cwidth, options.minWidth);
- }
- const rem = cwidth / 10;
- docEl.style.fontSize = rem + "px";
- }
- setRemUnit();
- window.addEventListener("resize", setRemUnit);
- window.addEventListener("pageshow", function (e) {
- if (e.persisted) {
- setRemUnit();
- }
- });
- if (dpr >= 2) {
- const fakeBody = document.createElement("body");
- const testElement = document.createElement("div");
- testElement.style.border = ".5px solid transparent";
- fakeBody.appendChild(testElement);
- docEl.appendChild(fakeBody);
- if (testElement.offsetHeight === 1) {
- docEl.classList.add("hairlines");
- }
- docEl.removeChild(fakeBody);
- }
- }
|