-
Notifications
You must be signed in to change notification settings - Fork 69
/
fade-in.html
112 lines (90 loc) · 2.51 KB
/
fade-in.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html>
<head>
<title>A-Frame: Environment component</title>
<meta name="description" content="A-Frame Examples">
<script src="js/aframe-master-v1.3.0.min.js"></script>
<script src="js/aframe-environment-component.min.js"></script>
<style>
.mainUI
{
border: 0px solid pink;
position: fixed;
top: 0px;
width:100%; height:100%;
z-index: 1;
pointer-events: none; /* allow click-through in transparent areas */
display: flex;
align-items: center;
justify-content: center;
}
.regionUI
{
border: 0px solid yellow;
position: absolute;
display: flex;
flex-direction: row;
pointer-events: none;
}
.buttonUI
{
border: 0px solid lime;
display: flex;
flex-direction: column;
justify-content: center;
pointer-events: auto;
filter: drop-shadow(0px 0px 20px white);
}
</style>
</head>
<body>
<div class="mainUI" id="uiDiv" oncontextmenu="return false;">
<!-- centered -->
<div class="regionUI">
<div class="buttonUI">
<img src="images/buttons/enter.png" id="buttonEnter" />
</div>
</div>
</div>
<script>
// runs when user clicks button
AFRAME.registerComponent('start', {
init: function()
{
// block pointer events until buttonEnter is clicked
let uiDiv = document.getElementById("uiDiv");
uiDiv.style["pointer-events"] = "auto";
// set up background blocker
uiDiv.style["background-color"] = "rgba(0, 0, 0, 0.75)";
// indicate clickable with hand cursor (desktop)
let buttonEnter = document.getElementById("buttonEnter");
buttonEnter.style.cursor = "pointer";
// fade-in functionality
let fadeIn = function()
{
// allow point events again
uiDiv.style["pointer-events"] = "none";
// sounds can only be triggered after a mouse interaction
let soundPlayer = document.querySelector("#ambientSound");
soundPlayer.components.sound.playSound();
// remove startButton
buttonEnter.parentNode.remove(buttonEnter);
// fade out uiDiv background
uiDiv.style["background-color"] = "rgba(0, 0, 0, 0.0)";
uiDiv.style["transition"] = "background-color 1000ms linear";
}
// activate for desktop/touchscreen
buttonEnter.addEventListener('touchstart', fadeIn);
buttonEnter.addEventListener('mousedown', fadeIn);
}
});
</script>
<!-- https://github.com/supermedium/aframe-environment-component -->
<a-scene environment="preset: default;" start>
<a-assets>
<audio id="ambient" src="audio/ambient-wind.mp3" preload="auto"></audio>
</a-assets>
<a-entity id="ambientSound" sound="src: #ambient; loop: true;"></a-entity>
</a-scene>
</body>
</html>