WebScene 实例具有处理场景幻灯片的 演示文稿 属性。 幻灯片的属性可用于创建 DOM 元素来表示每个视点。
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
// The view must be ready (or resolved) before you can// access the properties of the WebSceneview.when(() => {
// The slides are a collection inside the presentation// property of the WebSceneconst slides = scene.presentation.slides;
// Loop through each slide in the collection slides.forEach((slide) => {
// Create a new <div> element for each slide and place the title of// the slide in the element.const slideElement = document.createElement("div");
slideElement.id = slide.id;
slideElement.classList.add("slide");
// Create a <div> element to display the slide title text.const title = document.createElement("div");
title.innerText = slide.title.text;
slideElement.appendChild(title);
// Create a new <img> element and place it inside the newly created <div>.// This will reference the thumbnail from the slide.const img = new Image();
img.src = slide.thumbnail.url;
img.title = slide.title.text;
slideElement.appendChild(img);
});
});
为每张幻灯片创建新的 DOM 元素后,您可以设置一个单击事件处理程序以将幻灯片的设置应用于视图。 这是通过幻灯片的 applyTo() 方法完成的。