Разбираемся в CSS
Anonymous
Ширина прокрутки и ширина клиента остаются прежними при увеличении размера шрифта
Сообщение
Anonymous » 23 сен 2024, 03:58
У меня есть функция, которая увеличивает размер шрифта контейнера в зависимости от ширины прокрутки. Но когда я печатаю значения ScrollWidth и clientWidth в цикле while, они остаются прежними.
Код: Выделить всё
function adjustFontSize(textField) {
let fontSize = 10; // Starting font size
textField.style.fontSize = fontSize + "px";
// Increment font size until textField no longer fits
while (textField.scrollWidth
[code]
Document
#playerInfoContainer {
position: absolute;
top: 172px;
left: 0;
width: 267px;
height: 599px;
text-align: center;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.playerInfo {
width: 200px;
}
.playerInfo.winner {
color: red;
}
.playerInfoName {
font-family: UberEatsFat;
}
.playerInfoPercentage {
font-size: 25px;
font-family: UberEatsRegular;
}
Sané
9 (40,9%)
Hamm
8 (36,4%)
Gulászci
5 (22,7%)
const playerInfoContainer = document.getElementById("playerInfoContainer");
const playerInfoContainerChildren = playerInfoContainer.children;
Array.from(playerInfoContainerChildren).forEach((child) => {
console.log("child: ", child);
adjustFontSize(child);
});
function adjustFontSize(textField) {
let fontSize = 10; // Starting font size
textField.style.fontSize = fontSize + "px";
// Increment font size until textField no longer fits
console.log("textfield: ", textField);
console.log("scrollWidth: ", textField.scrollWidth);
console.log("clientWidth: ", textField.clientWidth);
while (textField.scrollWidth
Подробнее здесь: [url]https://stackoverflow.com/questions/79009556/scrollwidth-and-clientwidth-remain-the-same-while-increasing-fontsize[/url]
1727053094
Anonymous
У меня есть функция, которая увеличивает размер шрифта контейнера в зависимости от ширины прокрутки. Но когда я печатаю значения ScrollWidth и clientWidth в цикле while, они остаются прежними. [code]function adjustFontSize(textField) { let fontSize = 10; // Starting font size textField.style.fontSize = fontSize + "px"; // Increment font size until textField no longer fits while (textField.scrollWidth [code] Document #playerInfoContainer { position: absolute; top: 172px; left: 0; width: 267px; height: 599px; text-align: center; display: flex; flex-direction: column; justify-content: space-around; align-items: center; } .playerInfo { width: 200px; } .playerInfo.winner { color: red; } .playerInfoName { font-family: UberEatsFat; } .playerInfoPercentage { font-size: 25px; font-family: UberEatsRegular; } Sané 9 (40,9%) Hamm 8 (36,4%) Gulászci 5 (22,7%) const playerInfoContainer = document.getElementById("playerInfoContainer"); const playerInfoContainerChildren = playerInfoContainer.children; Array.from(playerInfoContainerChildren).forEach((child) => { console.log("child: ", child); adjustFontSize(child); }); function adjustFontSize(textField) { let fontSize = 10; // Starting font size textField.style.fontSize = fontSize + "px"; // Increment font size until textField no longer fits console.log("textfield: ", textField); console.log("scrollWidth: ", textField.scrollWidth); console.log("clientWidth: ", textField.clientWidth); while (textField.scrollWidth Подробнее здесь: [url]https://stackoverflow.com/questions/79009556/scrollwidth-and-clientwidth-remain-the-same-while-increasing-fontsize[/url]