<header>
<h2 class="title">MouseEvent -> clientY</h2>
<p class="description">Визначає вертикальну позицію курсора відносно видимої частини вікна.</p>
</header>
<main>
<div class="controls">
<label>
<input type="radio" name="sizeTarget" value="header" checked> Змінювати заголовок
</label>
<label>
<input type="radio" name="sizeTarget" value="text"> Змінювати текст
</label>
</div>
<div class="result" id="resultBox">
<h3 class="resizable" id="headerText">Це змінний заголовок</h3>
<p class="resizable" id="mainText">Цей текст змінюватиме розмір шрифту залежно від положення миші.</p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.controls {
margin-bottom: 15px;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
.resizable {
transition: font-size 0.2s ease;
}
document.addEventListener('mousemove', function(event) {
let clientY = event.clientY;
let windowHeight = window.innerHeight;
// Обчислюємо розмір шрифту відносно висоти вікна
let fontSize = 10 + (clientY / windowHeight) * 20;
// Вибір елементу для зміни розміру шрифту
let target = document.querySelector('input[name="sizeTarget"]:checked').value;
if (target === 'header') {
document.getElementById('headerText').style.fontSize = `${fontSize}px`;
} else if (target === 'text') {
document.getElementById('mainText').style.fontSize = `${fontSize}px`;
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.