Aha, teraz rozumiem! Chodzi o to, żeby tekst zaczynał się przewijać od 1/4 wysokości ekranu od góry (czyli 3/4 od dołu). Oto poprawiona wersja:
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prosty Prompter</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
/* Panel konfiguracyjny */
#config-panel {
padding: 20px;
max-width: 800px;
margin: 20px auto;
background: white;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
textarea {
width: 100%;
height: 200px;
margin-bottom: 15px;
padding: 10px;
box-sizing: border-box;
}
.control-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type=range], input[type=color], input[type=file] {
width: 100%;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
}
button:hover {
background-color: #45a049;
}
/* Ekran promptera */
#prompter-screen {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #000;
overflow: hidden;
cursor: pointer;
}
/* KLUCZOWA ZMIANA: padding-top 25vh (1/4 wysokości ekranu) */
#prompter-text {
color: white;
padding: 25vh 10% 50vh; /* 25vh od góry, 10% marginesy boczne, 50vh od dołu */
text-align: left;
line-height: 1.5;
transform: translateY(0);
will-change: transform;
}
/* Kontrolki */
#controls-overlay {
position: fixed;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background: rgba(255, 255, 255, 0.8);
padding: 10px;
border-radius: 5px;
display: none;
z-index: 10;
white-space: nowrap;
}
.speed-control {
margin: 0 10px;
display: inline-block;
}
#current-speed {
min-width: 70px;
text-align: center;
font-family: monospace;
font-weight: bold;
}
</style>
</head>
<body>
<!-- Panel konfiguracyjny -->
<div id="config-panel">
<h1>Ustawienia Promptera</h1>
<div class="control-group">
<label for="text-input">Wklej tekst lub załaduj plik .txt:</label>
<input type="file" id="file-input" accept=".txt" style="margin-bottom: 10px;">
<textarea id="text-input" placeholder="Wklej tutaj swój tekst..."></textarea>
</div>
<div class="control-group">
<label for="font-size">Wielkość czcionki: <span id="font-size-value">60</span>px</label>
<input type="range" id="font-size" min="20" max="150" value="60">
</div>
<div class="control-group">
<label for="speed">Szybkość przewijania: <span id="speed-value">0.1875</span></label>
<input type="range" id="speed" min="0.0125" max="1.25" value="0.1875" step="0.0125">
</div>
<div class="control-group">
<label for="font-color">Kolor czcionki:</label>
<input type="color" id="font-color" value="#FFFFFF">
</div>
<button onclick="startPrompter()">Startuj Prompter</button>
</div>
<!-- Ekran promptera -->
<div id="prompter-screen">
<div id="prompter-text"></div>
</div>
<!-- Kontrolki -->
<div id="controls-overlay">
<button onclick="togglePause()">Pauza/Wznów (Spacja)</button>
<button onclick="exitPrompter()">Wyjdź (Esc)</button>
<span class="speed-control">
Szybkość:
<button onclick="decreaseSpeed()">-</button>
<span id="current-speed">0.1875</span>
<button onclick="increaseSpeed()">+</button>
</span>
</div>
<script>
// Elementy DOM
const configPanel = document.getElementById('config-panel');
const prompterScreen = document.getElementById('prompter-screen');
const prompterText = document.getElementById('prompter-text');
const controlsOverlay = document.getElementById('controls-overlay');
const textInput = document.getElementById('text-input');
const fontSizeInput = document.getElementById('font-size');
const speedInput = document.getElementById('speed');
const fontColorInput = document.getElementById('font-color');
const fileInput = document.getElementById('file-input');
const currentSpeedDisplay = document.getElementById('current-speed');
// Zmienne stanu
let animationFrameId = null;
let isPaused = false;
let currentScrollY = 0;
let speed = 0.1875;
const speedStep = 0.0125;
const minSpeed = 0.0125;
const maxSpeed = 1.25;
let accumulatedDelta = 0;
// Funkcje pomocnicze
fontSizeInput.oninput = () => {
document.getElementById('font-size-value').innerText = fontSizeInput.value;
};
speedInput.oninput = () => {
const newSpeed = parseFloat(speedInput.value);
document.getElementById('speed-value').innerText = newSpeed.toFixed(4);
currentSpeedDisplay.innerText = newSpeed.toFixed(4);
speed = newSpeed;
};
function updateSpeedDisplay() {
currentSpeedDisplay.innerText = speed.toFixed(4);
}
function increaseSpeed() {
speed = Math.min(maxSpeed, speed + speedStep);
updateSpeedDisplay();
}
function decreaseSpeed() {
speed = Math.max(minSpeed, speed - speedStep);
updateSpeedDisplay();
}
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
textInput.value = e.target.result;
};
reader.readAsText(file);
}
});
// Funkcja przewijania
function scrollPrompter() {
if (isPaused) {
animationFrameId = requestAnimationFrame(scrollPrompter);
return;
}
accumulatedDelta += speed;
if (Math.abs(accumulatedDelta) >= 0.01) {
const pixelsToMove = Math.floor(accumulatedDelta);
currentScrollY -= pixelsToMove;
accumulatedDelta -= pixelsToMove;
prompterText.style.transform = `translateY(${currentScrollY}px)`;
}
// Punkt zatrzymania - tekst powinien przewinąć się, aż jego dolna krawędź minie 1/4 wysokości ekranu
const stopPoint = -(prompterText.offsetHeight - window.innerHeight * 0.25);
if (currentScrollY < stopPoint) {
stopScrolling();
} else {
animationFrameId = requestAnimationFrame(scrollPrompter);
}
}
function startScrolling() {
if (!animationFrameId) {
accumulatedDelta = 0;
animationFrameId = requestAnimationFrame(scrollPrompter);
}
}
function stopScrolling() {
if (animationFrameId) {
cancelAnimationFrame(animationFrameId);
animationFrameId = null;
}
}
// Główne funkcje kontrolne
function startPrompter() {
const text = textInput.value.replace(/\n/g, '<br>');
if (!text.trim()) {
alert("Proszę wkleić tekst lub załadować plik.");
return;
}
prompterText.style.fontSize = `${fontSizeInput.value}px`;
prompterText.style.color = fontColorInput.value;
speed = parseFloat(speedInput.value);
currentSpeedDisplay.innerText = speed.toFixed(4);
prompterText.innerHTML = text;
configPanel.style.display = 'none';
prompterScreen.style.display = 'block';
controlsOverlay.style.display = 'block';
currentScrollY = 0;
prompterText.style.transform = `translateY(0px)`;
isPaused = false;
startScrolling();
}
function togglePause() {
isPaused = !isPaused;
}
function exitPrompter() {
stopScrolling();
configPanel.style.display = 'block';
prompterScreen.style.display = 'none';
controlsOverlay.style.display = 'none';
}
// Kontrola klawiaturą
document.addEventListener('keydown', (e) => {
if (prompterScreen.style.display === 'block') {
if (e.code === 'Space') {
e.preventDefault();
togglePause();
}
if (e.code === 'Escape') {
exitPrompter();
}
if (e.code === 'ArrowUp') {
e.shiftKey ? speed = Math.min(maxSpeed, speed + speedStep/2) : increaseSpeed();
e.preventDefault();
updateSpeedDisplay();
}
if (e.code === 'ArrowDown') {
e.shiftKey ? speed = Math.max(minSpeed, speed - speedStep/2) : decreaseSpeed();
e.preventDefault();
updateSpeedDisplay();
}
}
});
</script>
</body>
</html>
Kluczowe zmiany:
-
CSS dla #prompter-text:
padding: 25vh 10% 50vh; /* 25vh od góry (1/4 wysokości), 10% marginesy boczne, 50vh od dołu */
-
Logika zatrzymania przewijania:
const stopPoint = -(prompterText.offsetHeight - window.innerHeight * 0.25);
Teraz tekst zaczyna się dokładnie na wysokości 1/4 ekranu od góry (czyli 3/4 od dołu) i przewija się płynnie w górę.