Хорошо, давайте разместим поезд вертикально с правой стороны экрана. Я внесу изменения, чтобы поезд появлялся справа, и убедимся, что он видим и правильно расположен.
Вот обновленный код:
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Дембель</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: space-around;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
flex-direction: column;
position: relative;
}
.container {
text-align: center;
}
.progress-bar {
width: 100%;
background-color: #e0e0e0;
border-radius: 5px;
margin-top: 10px;
}
.progress {
height: 30px;
background-color: #76c7c0;
border-radius: 5px;
transition: width 0.5s;
}
#clock {
width: 150px;
height: 150px;
background-image: url('Chas.png');
background-size: cover;
background-position: center;
animation: swing 2s infinite alternate;
}
@keyframes swing {
0% { transform: rotate(-5deg); }
100% { transform: rotate(5deg); }
}
#scrolling-text {
position: absolute;
top: 20px;
width: 100%;
text-align: center;
overflow: hidden;
white-space: nowrap;
box-sizing: border-box;
animation: scroll 10s linear infinite;
font-weight: bold;
font-size: 20px;
}
@keyframes scroll {
0% { transform: translateX(100%); }
100% { transform: translateX(-100%); }
}
#match-date {
margin-top: 20px;
font-weight: bold;
font-size: 22px;
}
#train {
cursor: grab;
position: absolute;
bottom: 10px;
right: 10px; /* Расположение поезда справа */
width: 100px; /* Убедитесь, что ширина поезда выставлена корректно */
height: auto; /* Поддерживаем пропорции */
}
.track {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 5px;
background-color: #333;
}
</style>
</head>
<body>
<div id="scrolling-text"></div>
<div class="container">
<h2>До дембеля 6.12.2025</h2>
<div id="time-remaining-1"></div>
<div id="served-time-1"></div>
<div class="progress-bar">
<div id="progress-1" class="progress"></div>
</div>
</div>
<div id="clock"></div>
<div class="container">
<h2>До дембеля 4.07.2025</h2>
<div id="time-remaining-2"></div>
<div id="served-time-2"></div>
<div class="progress-bar">
<div id="progress-2" class="progress"></div>
</div>
</div>
<div id="match-date"></div>
<div class="track"></div> <!-- Дорога для поезда -->
<svg id="train" width="100" height="100" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg">
<g>
<rect width="100" height="20" fill="#663300" />
<g>
<path d="M272.8,277.5h-56.2v-72.9c0-9.7,7.9-17.6,17.6-17.6h21c9.7,0,17.6,7.9,17.6,17.6V277.5z" fill="#eee" />
</g>
<rect width="50" height="20" x="50" y="275" fill="gray" rx="5" />
</g>
</svg>
<script>
let isDragging = false;
const train = document.getElementById('train');
train.addEventListener('mousedown', (e) => {
isDragging = true;
train.style.cursor = 'grabbing';
});
document.addEventListener('mouseup', () => {
isDragging = false;
train.style.cursor = 'grab';
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
const mouseX = e.clientX;
const offsetX = train.offsetWidth / 2; // Корректировка по центру поезда
train.style.left = (mouseX - offsetX) + 'px'; // Движение по горизонтали
}
});
const dembelDate1 = new Date('2025-12-06');
const dembelDate2 = new Date('2025-07-04');
const enlistmentDate1 = new Date('2024-12-06');
const enlistmentDate2 = new Date('2024-07-04');
function updateProgress() {
const now = new Date();
const timeRemaining1 = dembelDate1 - now;
const totalTime1 = dembelDate1 - enlistmentDate1;
const progress1 = Math.max(0, (totalTime1 - timeRemaining1) / totalTime1) * 100;
const timeRemaining2 = dembelDate2 - now;
const totalTime2 = dembelDate2 - enlistmentDate2;
const progress2 = Math.max(0, (totalTime2 - timeRemaining2) / totalTime2) * 100;
const servedTime1 = now - enlistmentDate1;
const servedTime2 = now - enlistmentDate2;
document.getElementById('time-remaining-1').textContent = formatTime(timeRemaining1);
document.getElementById('served-time-1').textContent = `Уже отслужил: ${formatTime(servedTime1)}`;
document.getElementById('progress-1').style.width = progress1 + '%';
document.getElementById('time-remaining-2').textContent = formatTime(timeRemaining2);
document.getElementById('served-time-2').textContent = `Уже отслужил: ${formatTime(servedTime2)}`;
document.getElementById('progress-2').style.width = progress2 + '%';
checkMatchDate(servedTime1, timeRemaining2);
}
function checkMatchDate(servedTime1, remainingTime2) {
const servedDays1 = Math.floor(servedTime1 / (1000 * 60 * 60 * 24));
const remainingDays2 = Math.floor(remainingTime2 / (1000 * 60 * 60 * 24));
const matchDays = remainingDays2 - servedDays1;
if (matchDays > 0) {
const matchDate = new Date();
matchDate.setDate(matchDate.getDate() + matchDays);
document.getElementById('scrolling-text').textContent = `Молодые отслужат столько же через ${matchDays} дн.`;
document.getElementById('match-date').textContent = `Совпадение: ${formatDate(matchDate)}`;
} else if (matchDays === 0) {
document.getElementById('scrolling-text').textContent = "Молодые отслужат столько же, сколько осталось дедам!";
document.getElementById('match-date').textContent = "Сегодня совпадение!";
} else {
document.getElementById('scrolling-text').textContent = `Молодые никогда не отслужат столько же!`;
document.getElementById('match-date').textContent = "";
}
}
function formatTime(milliseconds) {
const days = Math.floor(milliseconds / (1000 * 60 * 60 * 24));
const hours = Math.floor((milliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((milliseconds % (1000 * 60 * 60)) / (1000 * 60));
return `${days} дн. ${hours} ч. ${minutes} мин.`;
}
function formatDate(date) {
const options = { year: 'numeric', month: '2-digit', day: '2-digit' };
return date.toLocaleDateString('ru-RU', options);
}
setInterval(updateProgress, 1000);
updateProgress();
</script>
</body>
</html>
Основные изменения:
-
Размещение поезда: Поезд теперь расположен справа от экрана. Я добавил right: 10px;, чтобы он отображался ближе к правому краю.
-
Размеры поезда: Убедитесь, что ширина лучшего сохранилась для лучшей визуализации. Вы можете настроить width и height SVG поезда, чтобы получать желаемый размер.
В этом коде поезд будет виден справа, и его можно будет перетаскивать с помощью мыши. Если у вас возникнут вопросы или необходимость в дополнительных изменениях, дайте знать!