calc
unknown
javascript
3 years ago
1.4 kB
2
Indexable
Never
// Scale Config var screenFix = document.querySelector('body'); var container_width = 1366; var container_height = 769; // Em % (ex: 10%) var margin = 10; // Scale var initScale = true; var can_scale = true; var resize_list; var orient_list; function calcScale() { if (!can_scale) { window.removeEventListener("resize", resize_list); window.removeEventListener("orientationchange", orient_list); return console.log('Não pode escalar'); } mobileAndTabletCheck(); if (initScale) { initScale = false; setTimeout(function () { window.addEventListener("resize", resize_list = function () { calcScale(); }); window.addEventListener("orientationchange", orient_list = function () { calcScale(); }); }, 500); } let pivWidth; let pivHeight; pivWidth = screenFix.clientWidth / container_width; pivHeight = screenFix.clientHeight / container_height; pivWidth = pivWidth.toFixed(3); pivHeight = pivHeight.toFixed(3); let pivScale = pivHeight > pivWidth ? pivWidth : pivHeight; pivScale = pivScale - (margin / 100); try { $("#container").css("transform", `translate(-50%, -50%) scale(${pivScale})`); $("#container").css("top", "50%"); $("#container").css("left", "50%"); } catch (err) { console.log("Scale Fail =>\n", err) } }