스트림이 활성 상태인지에 따라 페이지 요소를 보이거나 숨기세요. 이렇게 하면 게임이 시작될 때 사라지는 스트림 전 랜딩 UI와, 게임 플레이 중에 나타나는 스트림 중 컨트롤을 만들 수 있습니다.
표시 여부 전환
전환하려는 모든 요소에 .yom-toggle-visibility 클래스와 data-yom-stream-id를 추가하세요.
<!-- Visible before stream, hidden during stream -->
<div class="yom-toggle-visibility" data-yom-stream-id="1">
<h2>Welcome! Click below to start playing.</h2>
<button class="yom-launch-button" data-yom-stream-id="1">Play Now</button>
</div>
<!-- Hidden before stream, visible during stream -->
<div class="yom-toggle-visibility" data-yom-stream-id="1" style="display: none;">
<p>Game is running. Use the controls below:</p>
<button onclick="window.postToPlayer('1', 'SpawnBot', {amount: '1'})">Add Bot</button>
</div>
작동 방식:
- 스트림이 활성 상태가 되면(
playerReady) 요소가 전환됩니다. 보이던 요소는 서서히 사라지고, 숨겨져 있던 요소는 서서히 나타납니다. - 스트림이 닫히면(
streamClosed) 요소는 원래 상태로 다시 전환됩니다.
CSS 전환 효과
페이드 애니메이션은 300ms입니다. 전환이 부드럽도록 다음 CSS를 추가하세요.
.yom-toggle-visibility {
transition: opacity 0.3s ease;
}
컨테이너 훅
스트림이 실행 중일 때 아무 컨테이너 요소에나 .yom-active 클래스를 적용하려면 .yom-player-placeholder에 data-hook을 사용하세요.
<div id="game-section">
<div class="yom-player-placeholder"
data-yom-stream-id="1"
data-game-id="my-game"
data-hook="#game-section"
style="width: 100%; aspect-ratio: 16/9;">
</div>
</div>
이제 CSS로 활성 상태의 스타일을 지정할 수 있습니다.
#game-section.yom-active {
background: #000;
padding: 0;
max-width: 100%;
}
.yom-active 클래스는 스트림이 시작될 때 추가되고 끝날 때 제거되므로, 레이아웃 변경을 CSS로 완전히 통제할 수 있습니다.