<div></div>
body { overflow: hidden; } div { position: absolute; font-family: Arial; color: #fff; background: #5aa348; }
var docWidth, docHeight, docRatio, div = document.getElementsByTagName('div')[0]; onresize = function() { docWidth = document.body.clientWidth; docHeight = document.body.clientHeight; // docRatio = docWidth / docHeight; // fullScreenProportionalElem(div, 1920, 1080); // , , resizeFont(div, 1920, 1080, 200); // , , , // } function fullScreenProportionalElem(elem, width, height) { var ratio = width / height; // if (docRatio < ratio) { elem.style.width = docWidth + 'px'; elem.style.height = Math.round(docWidth / ratio) + 'px'; elem.style.top = Math.round(docHeight / 2 - elem.offsetHeight / 2) + 'px'; elem.style.left = '0px'; // // , , } else if (docRatio > ratio) { elem.style.width = Math.round(docHeight * ratio) + 'px'; elem.style.height = docHeight + 'px'; elem.style.top = '0px'; elem.style.left = Math.round(docWidth / 2 - elem.offsetWidth / 2) + 'px'; // // , , } else { elem.style.width = docWidth + 'px'; elem.style.height = docHeight + 'px'; elem.style.top = '0px'; elem.style.left = '0px'; // // , top left } } function resizeFont(elem, width, height, size) { var ratio = width / height; // if (docRatio < ratio) elem.style.fontSize = height * size / 14062 + 'vw'; else if (docRatio > ratio) elem.style.fontSize = width * size / 14062 + 'vh'; // 14062 , } onresize(); //
Source: https://habr.com/ru/post/187406/
All Articles