forked from google/model-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazy-loading.html
222 lines (195 loc) · 8.47 KB
/
lazy-loading.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!--
/*
* Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title><model-viewer> Lazy Loading</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no,
minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" href="styles/examples.css" rel="stylesheet" />
<link rel="shortcut icon" type="image/png" href="assets/favicon.png" />
<!-- The following libraries and polyfills are recommended to maximize browser support -->
<!-- 🚨 REQUIRED: Web Components polyfill to support Edge and Firefox < 63 -->
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<!-- 💁 OPTIONAL: Intersection Observer polyfill for better performance in Safari and IE11 -->
<script src="../node_modules/intersection-observer/intersection-observer.js"></script>
<!-- 💁 OPTIONAL: Resize Observer polyfill improves resize behavior in non-Chrome browsers -->
<script src="../node_modules/resize-observer-polyfill/dist/ResizeObserver.js"></script>
<!-- 💁 OPTIONAL: Fullscreen polyfill is required for experimental AR features in Canary -->
<!--<script src="../node_modules/fullscreen-polyfill/dist/fullscreen.polyfill.js"></script>-->
<!-- 💁 OPTIONAL: Include prismatic.js for Magic Leap support -->
<!--<script src="../node_modules/@magicleap/prismatic/prismatic.min.js"></script>-->
<style>
#button-load {
background-image: url(assets/ic_get_app_white_24dp.svg);
background-repeat: no-repeat;
background-size: 24px 24px;
background-position: 6% 50%;
background-color: #000;
color: white;
cursor: pointer;
border-radius: 6px;
display: inline-block;
padding: 10px 18px 9px 40px;
font-weight: 500;
box-shadow: 0 0 8px rgba(0,0,0,.2), 0 0 4px rgba(0,0,0,.25);
position: absolute;
left: 50%;
top: 50%;
transform: translate3d(-50%, -50%, 0);
z-index: 100;
}
#lazy-load-poster {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-image: url(assets/poster-damagedhelmet.png);
background-size: cover;
background-position: 50% 50%;
}
</style>
</head>
<body>
<div class="sample">
<div id="demo-container-1" class="demo"></div>
<div class="content">
<div class="wrapper">
<a class="lockup" href="../index.html"><div class="icon-button icon-modelviewer-black"></div><h1>examples</h1></a>
<h4 id="intro"><span class="font-medium">Lazy Loading. </span>Improve UX with these cost-saving <model-viewer> configurations. This page tests usages of the <model-viewer> element using the poster attribute.</h4>
<div class="heading">
<h2 class="demo-title">Display a poster until loaded</h2>
<h4></h4>
</div>
<example-snippet stamp-to="demo-container-1" highlight-as="html">
<template>
<model-viewer id="reveal" preload camera-controls auto-rotate poster="assets/poster-shishkebab.png" src="assets/shishkebab.glb" alt="A 3D model of a shishkebab"></model-viewer>
</template>
</example-snippet>
</div>
</div>
</div>
<div class="sample">
<div id="demo-container-2" class="demo"></div>
<div class="content">
<div class="wrapper">
<div class="heading">
<h2 class="demo-title">Preload with poster and show model on interaction</h2>
<h4></h4>
</div>
<example-snippet stamp-to="demo-container-2" highlight-as="html">
<template>
<!-- use unique asset to ensure preloading -->
<model-viewer id="interaction" camera-controls preload reveal="interaction" poster="assets/poster-sphere.png" src="assets/reflective-sphere.gltf" alt="A 3D model of a reflective sphere"></model-viewer>
</template>
</example-snippet>
</div>
</div>
</div>
<div class="sample">
<div id="demo-container-3" class="demo"></div>
<div class="content">
<div class="wrapper">
<div class="heading">
<h2 class="demo-title">Customize loading experience with your own HTML</h2>
<!-- <h2 class="demo-title">Lazy load with poster until interaction</h2> -->
<h4></h4>
</div>
<example-snippet stamp-to="demo-container-3" highlight-as="html">
<template>
<!-- use unique asset to ensure lazy loading -->
<model-viewer id="lazy-load" camera-controls reveal="interaction" poster="assets/poster-damagedhelmet.png" src="assets/DamagedHelmet/DamagedHelmet.gltf" alt="A 3D model of a damaged helmet">
<div id="lazy-load-poster" slot="poster"></div>
<div id="button-load" slot="poster">Load 3D Model</div>
</model-viewer>
</template>
</example-snippet>
</div>
</div>
</div>
<div class="sample">
<div id="demo-container-4" class="demo"></div>
<div class="content">
<div class="wrapper">
<div class="heading">
<h2 class="demo-title">Poster with invalid model</h2>
<h4></h4>
</div>
<example-snippet stamp-to="demo-container-4" highlight-as="html">
<template>
<model-viewer poster="assets/poster-astronaut.png" src="i-do-not-exist.glb" alt="An invalid model"></model-viewer>
</template>
</example-snippet>
</div>
</div>
</div>
<div class="sample">
<div id="demo-container-5" class="demo"></div>
<div class="content">
<div class="wrapper">
<div class="heading">
<h2 class="demo-title">Cycling between posters</h2>
<h4></h4>
</div>
<example-snippet stamp-to="demo-container-5" highlight-as="html">
<template>
<model-viewer id="toggle-poster" reveal="interaction" auto-rotate poster="assets/poster-astronaut.png" src="assets/Astronaut.glb" alt="A 3D model of an astronaut"></model-viewer>
<script>
const posters = ['poster-astronaut2.png', 'poster-astronaut3.png', 'poster-astronaut4.png'];
let i = 0;
setInterval(() =>
$('#toggle-poster').setAttribute('poster', `assets/${posters[i++ % 2]}`), 2000);
</script>
</template>
</example-snippet>
</div>
</div>
</div>
<div class="footer">
<ul>
<li class="attribution">
<a href="https://poly.google.com/view/dLHpzNdygsg">Astronaut</a> by <a href="https://poly.google.com/user/4aEd8rQgKu2">Poly</a>,
licensed under <a href="https://creativecommons.org/licenses/by/2.0/">CC-BY</a>.
</li>
<li class="attribution">
<a href="https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/DamagedHelmet">Damaged Helmet</a> by <a href="https://sketchfab.com/theblueturtle_">theblueturtle_</a>,
licensed under <a href="https://creativecommons.org/licenses/by-nc/3.0/us/">Creative Commons Attribution-NonCommercial</a>.
</li>
<li class="attribution">
<a href="https://poly.google.com/view/6uTsH2jqgVn">Shish kebab</a> by <a href="https://poly.google.com/user/4aEd8rQgKu2">Poly</a>,
licensed under <a href="https://creativecommons.org/licenses/by/2.0/">CC-BY</a>.
</li>
</ul>
<div style="margin-top:24px;" class="copyright">©Copyright 2018 Google Inc. Licensed under the Apache License 2.0.</div>
<div><a href="https://github.com/GoogleWebComponents/model-viewer">Github</a> ∙ <a href="https://model-viewer.glitch.me/">Glitch</a> ∙ <a href="https://github.com/GoogleWebComponents/model-viewer/issues">Bug report</a></div>
</div>
<script src="./scripts/helpers.js"></script>
<!-- Documentation-specific dependencies: -->
<script type="module" src="./built/dependencies.js">
</script>
<script nomodule src="./built/dependencies-legacy.js">
</script>
<!-- Loads <model-viewer> only on modern browsers: -->
<script type="module" src="../dist/model-viewer.js">
</script>
<!-- Loads <model-viewer> only on old browsers like IE11: -->
<script nomodule src="../dist/model-viewer-legacy.js">
</script>
</body>
</html>