вот мой код целиком оптемезируй только javascript
#choices {
position: absolute;
display: grid;
grid-template-columns: repeat(3, 200px);
grid-template-rows: repeat(3, 50px);
left: calc(50% - 350px);
bottom: 100px;
gap: 50px;
}
.choice-button {
display: flex;
justify-content: flex-end;
align-items: center;
}
.choice-button button {
box-sizing: border-box;
border: none;
width: 284px;
padding: 15px;
font-size: 36px;
border-radius: 10px;
box-sizing: border-box;
color: #fff;
background: linear-gradient(90deg, rgba(0, 0, 0, 0.5) 0%, rgba(102, 102, 102, 0) 100%);
font-size: 24px;
font-weight: 700;
text-align: left;
cursor: none;
transition: all 700ms;
}
.choice-button_center button {
text-align: center;
border-radius: 50px;
background: linear-gradient(270deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.5) 100%);
}
#cell-2 {
transform: translateY(-50px);
}
#cell-8 {
transform: translateY(50px);
}
#cell-4 {
transform: translateX(-50px);
}
#cell-6 {
transform: translateX(50px);
}
#cell-1 button,
#cell-4 button,
#cell-7 button {
background: linear-gradient(270deg, rgba(0, 0, 0, 0.5) 0%, rgba(102, 102, 102, 0) 100%);
text-align: right;
border-top-right-radius: 50px;
border-bottom-right-radius: 50px;
}
#cell-1 button:hover,
#cell-4 button:hover,
#cell-7 button:hover {
background: linear-gradient(270deg, rgba(255, 255, 255, 0.5) 0%, rgba(102, 102, 102, 0) 95.77%);
}
#cell-3 button,
#cell-6 button,
#cell-9 button {
background: linear-gradient(90deg, rgba(0, 0, 0, 0.5) 0%, rgba(102, 102, 102, 0) 100%);
text-align: left;
border-top-left-radius: 50px;
border-bottom-left-radius: 50px;
}
#cell-3 button:hover,
#cell-6 button:hover,
#cell-9 button:hover {
background: linear-gradient(90deg, rgba(255, 255, 255, 0.5) 0%, rgba(102, 102, 102, 0) 95.77%);
}
#cell-2 button:hover,
#cell-8 button:hover {
background: linear-gradient(90deg, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 95.77%);
}
.choice-button:nth-child(5) {
background: unset;
text-align: unset;
border-top-right-radius: unset;
border-bottom-right-radius: unset;
}
.choice-button_hidden {
visibility: hidden;
}
.choice-button_controls {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: unset;
}
.choice-button_circle {
position: relative;
width: 100px;
height: 100px;
border-radius: 50%;
border: none;
background: rgba(0, 0, 0, 0.5);
transition: all 700ms;
}
.choice-button_circle::before {
content: "";
position: absolute;
top: -60px;
width: 90px;
height: 90px;
background: url("./arrow.svg");
background-repeat: no-repeat;
background-position: center;
transform: translateX(5%);
}
.choice-button_circle::after {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: transform 0.3s ease;
content: "";
width: 60px;
height: 60px;
border: 10px solid rgba(255, 255, 255, 0.251);
border-radius: 50%;
background: transparent;
box-shadow: 0px 0px 18px 0px rgba(255, 255, 255, 0.25);
}
.choice-button_circle:hover {
transform: rotate(90deg);
}
</style>
</div>
</div>
<div id="cell-6" class="choice-button_hidden choice-button"></div>
<div id="cell-7" class="choice-button_hidden choice-button"></div>
<div id="cell-8" class="choice-button_hidden choice-button choice-button_center"></div>
<div id="cell-9" class="choice-button_hidden choice-button"></div>
</div>
<script>
const video = document.getElementById('video');
const videoSource = document.getElementById('video-source');
const choicesContainer = document.getElementById('choices');
// Структура данных с актами
const acts = [
{
number: 1,
choices: [
{ text: 'Yes', nextAct: false, steptime: 166, stopstep: 12, goNext: 2, direction: 'left-center' },
{ text: 'No', nextAct: 2, direction: 'right-center' },
],
background: "./video1.mp4", // Название исходного видео для акта
time: 0,
stoptime: 5,
},
{
number: 2,
choices: [
{ text: 'Option 1', nextAct: false, steptime: 200, stopstep: 10, goNext: 3, direction: 'top-center' },
{ text: 'Option 2', nextAct: false, steptime: 150, stopstep: 8, goNext: 4, direction: 'left-top' },
],
background: "./video2.mp4",
time: 0,
stoptime: 14,
},
];
function setupEventListeners() {
const arrow = document.getElementById('arrow'); // Стрелка, которую нужно повернуть
const buttons = document.querySelectorAll('.choice-button button'); // Все кнопки в .choice-button
buttons.forEach(button => {
button.addEventListener('mouseenter', function () {
const direction = this.getAttribute('data-direction'); // Получаем направление для стрелки
console.log('Button direction:', direction); // Для отладки
switch (direction) {
case 'left-top':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(-45deg)';
break;
case 'right-top':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(45deg)';
break;
case 'left-bot':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(-135deg)';
break;
case 'right-bot':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(135deg)';
break;
case 'left-center':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(-90deg)';
break;
case 'right-center':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(90deg)';
break;
case 'top-center':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(0deg)';
break;
case 'top-right':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(60deg)';
break;
case 'top-left':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(-60deg)';
break;
case 'center':
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(0deg)';
break;
default:
arrow.style.transform = 'rotate(0deg)';
break;
}
});
// Возврат стрелки в исходное положение при уходе мыши с кнопки
button.addEventListener('mouseleave', function () {
arrow.style.transition = 'transform 0.5s ease';
arrow.style.transform = 'rotate(0deg)';
});
});
}
// Объект для отображения направлений в id ячеек
const directionToCell = {
'left-top': 'cell-1',
'top-center': 'cell-2',
'top-right': 'cell-3',
'left-center': 'cell-4',
'center': 'cell-5',
'right-center': 'cell-6',
'left-bottom': 'cell-7',
'center-bottom': 'cell-8',
'right-bottom': 'cell-9',
};
function generateButtons(choices) {
// Скрываем все кнопки на время
document.querySelectorAll('.choice-button button').forEach(button => {
button.classList.add('choice-button_hidden');
});
choices.forEach(choice => {
const cellId = directionToCell[choice.direction]; // Получаем id ячейки по направлению
const cell = document.getElementById(cellId);
if (cell) {
// Убираем класс скрытия с ячеек, где будут кнопки
cell.classList.remove('choice-button_hidden');
const button = document.createElement("button");
button.textContent = choice.text;
// Добавляем атрибут data-direction
button.setAttribute('data-direction', choice.direction);
// Добавляем обработчик для выбора
button.addEventListener('click', () => handleChoice(choice));
// Добавляем кнопку в ячейку
cell.appendChild(button);
document.getElementById('arrow').style.display = 'block';
}
});
// Обновляем события для стрелки
setupEventListeners();
}
function handleChoice(choice) {
// Удаляем все кнопки из DOM
document.querySelectorAll('.choice-button button').forEach(button => {
button.remove(); // Удаляем кнопку из DOM
});
document.getElementById('arrow').style.display = 'none';
if (choice.nextAct) {
loadAct(choice.nextAct);
} else {
// Логика для времени и других переходов
video.currentTime = choice.steptime;
video.play();
setTimeout(() => {
video.pause();
loadAct(choice.goNext);
}, choice.stopstep * 1000);
}
}
// Загрузка акта
function loadAct(actNumber) {
const act = acts.find(a => a.number === actNumber);
if (act) {
// Проверяем, нужно ли сменить видео
const newFileName = act.background;
video.currentTime = act.time;
video.play();
setTimeout(() => {
video.pause();
generateButtons(act.choices); // Генерируем кнопки для выбора
}, act.stoptime * 1000);
}
}
// Инициализация
loadAct(1); // Начинаем с первого акта
</script>