<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Пример JavaScript</title>
<style>
/* Общие стили */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, sans-serif;
}
body {
background-color: #f9f9f9;
color: #333;
line-height: 1.6;
}
header {
background-color: #2c3e50;
color: white;
padding: 1rem 2rem;
text-align: center;
}
main {
padding: 2rem;
max-width: 900px;
margin: 0 auto;
}
h1, h2, h3 {
margin-bottom: 1rem;
color: #2980b9;
}
.btn {
background-color: #3498db;
color: white;
border: none;
padding: 0.5rem 1rem;
margin: 0.5rem 0;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #2980b9;
}
.animated-box {
width: 100px;
height: 100px;
background-color: #e74c3c;
margin: 2rem 0;
transition: transform 0.5s ease;
}
.animated-box.moved {
transform: translateX(200px);
}
footer {
background-color: #34495e;
color: #ecf0f1;
text-align: center;
padding: 1rem;
margin-top: 3rem;
}
/* Модальное окно */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
}
.modal-content {
background-color: white;
margin: 10% auto;
padding: 2rem;
border-radius: 8px;
width: 80%;
max-width: 500px;
text-align: center;
}
.close-btn {
background-color: #e74c3c;
color: white;
border: none;
padding: 0.3rem 0.6rem;
margin-top: 1rem;
cursor: pointer;
border-radius: 4px;
}
</style>
</head>
<body>
<header>
<h1>Демонстрация JavaScript</h1>
</header>
<main>
<h2>Заголовок 2: Интерактивность</h2>
<p>Нажмите кнопку, чтобы переместить красный квадрат:</p>
<button id="moveBtn" class="btn">Переместить квадрат</button>
<div id="box" class="animated-box"></div>
<h2>Заголовок 3: Модальное окно</h2>
<p>Нажмите кнопку, чтобы открыть модальное окно:</p>
<button id="openModalBtn" class="btn">Показать модальное окно</button>
<h2>Заголовок 4: Динамическое обновление</h2>
<p>Текущее время: <span id="timeDisplay">—</span></p>
<button id="updateTimeBtn" class="btn">Обновить время</button>
</main>
{/* Модальное окно */}
<div id="myModal" class="modal">
<div class="modal-content">
<h3>Модальное окно</h3>
<p>Это простое модальное окно, созданное с помощью JavaScript.</p>
<button id="closeModalBtn" class="close-btn">Закрыть</button>
</div>
</div>
<footer>
<p>© 2026 Пример JavaScript-демонстрации</p>
</footer>
<script>
// Перемещение квадрата
const box = document.getElementById('box');
const moveBtn = document.getElementById('moveBtn');
moveBtn.addEventListener('click', () => {
box.classList.toggle('moved');
});
// Модальное окно
const modal = document.getElementById('myModal');
const openModalBtn = document.getElementById('openModalBtn');
const closeModalBtn = document.getElementById('closeModalBtn');
openModalBtn.addEventListener('click', () => {
modal.style.display = 'block';
});
closeModalBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
// Закрытие модального окна при клике вне его содержимого
window.addEventListener('click', (event) => {
if (event.target === modal) {
modal.style.display = 'none';
}
});
// Обновление времени
const timeDisplay = document.getElementById('timeDisplay');
const updateTimeBtn = document.getElementById('updateTimeBtn');
function updateTime() {
const now = new Date();
timeDisplay.textContent = now.toLocaleTimeString();
}
updateTimeBtn.addEventListener('click', updateTime);
updateTime(); // Инициализация времени при загрузке
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Пример JavaScript</title>
<style>
/* Общие стили */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, sans-serif;
}
body {
background-color: #f9f9f9;
color: #333;
line-height: 1.6;
}
header {
background-color: #2c3e50;
color: white;
padding: 1rem 2rem;
text-align: center;
}
main {
padding: 2rem;
max-width: 900px;
margin: 0 auto;
}
h1, h2, h3 {
margin-bottom: 1rem;
color: #2980b9;
}
.btn {
background-color: #3498db;
color: white;
border: none;
padding: 0.5rem 1rem;
margin: 0.5rem 0;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #2980b9;
}
.animated-box {
width: 100px;
height: 100px;
background-color: #e74c3c;
margin: 2rem 0;
transition: transform 0.5s ease;
}
.animated-box.moved {
transform: translateX(200px);
}
footer {
background-color: #34495e;
color: #ecf0f1;
text-align: center;
padding: 1rem;
margin-top: 3rem;
}
/* Модальное окно */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
}
.modal-content {
background-color: white;
margin: 10% auto;
padding: 2rem;
border-radius: 8px;
width: 80%;
max-width: 500px;
text-align: center;
}
.close-btn {
background-color: #e74c3c;
color: white;
border: none;
padding: 0.3rem 0.6rem;
margin-top: 1rem;
cursor: pointer;
border-radius: 4px;
}
</style>
</head>
<body>
<header>
<h1>Демонстрация JavaScript</h1>
</header>
<main>
<h2>Заголовок 2: Интерактивность</h2>
<p>Нажмите кнопку, чтобы переместить красный квадрат:</p>
<button id="moveBtn" class="btn">Переместить квадрат</button>
<div id="box" class="animated-box"></div>
<h2>Заголовок 3: Модальное окно</h2>
<p>Нажмите кнопку, чтобы открыть модальное окно:</p>
<button id="openModalBtn" class="btn">Показать модальное окно</button>
<h2>Заголовок 4: Динамическое обновление</h2>
<p>Текущее время: <span id="timeDisplay">—</span></p>
<button id="updateTimeBtn" class="btn">Обновить время</button>
</main>
{/* Модальное окно */}
<div id="myModal" class="modal">
<div class="modal-content">
<h3>Модальное окно</h3>
<p>Это простое модальное окно, созданное с помощью JavaScript.</p>
<button id="closeModalBtn" class="close-btn">Закрыть</button>
</div>
</div>
<footer>
<p>© 2026 Пример JavaScript-демонстрации</p>
</footer>
<script>
// Перемещение квадрата
const box = document.getElementById('box');
const moveBtn = document.getElementById('moveBtn');
moveBtn.addEventListener('click', () => {
box.classList.toggle('moved');
});
// Модальное окно
const modal = document.getElementById('myModal');
const openModalBtn = document.getElementById('openModalBtn');
const closeModalBtn = document.getElementById('closeModalBtn');
openModalBtn.addEventListener('click', () => {
modal.style.display = 'block';
});
closeModalBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
// Закрытие модального окна при клике вне его содержимого
window.addEventListener('click', (event) => {
if (event.target === modal) {
modal.style.display = 'none';
}
});
// Обновление времени
const timeDisplay = document.getElementById('timeDisplay');
const updateTimeBtn = document.getElementById('updateTimeBtn');
function updateTime() {
const now = new Date();
timeDisplay.textContent = now.toLocaleTimeString();
}
updateTimeBtn.addEventListener('click', updateTime);
updateTime(); // Инициализация времени при загрузке
</script>
</body>
</html>