@@ -60,16 +60,6 @@ This can be read as follows: "I want to retrieve 10 cat gif images with a small
60
60
61
61
With this result:
62
62
63
- ::: {#cat-container .cell-html}
64
- <!-- carousel with 10 cat images -->
65
- <div class =" carousel-container " >
66
- <div class =" carousel-wrapper " >
67
- <!-- Images will be inserted here by JavaScript -->
68
- </div >
69
- <button class =" carousel-button prev " >←</button >
70
- <button class =" carousel-button next " >→</button >
71
- </div >
72
-
73
63
``` {ojs}
74
64
cats = FileAttachment("../_data/cats.json").json()
75
65
@@ -111,45 +101,3 @@ viewof carousel = {
111
101
return container;
112
102
}
113
103
```
114
-
115
-
116
- <script >
117
- document .addEventListener (' DOMContentLoaded' , async () => {
118
- try {
119
- // Wait for Observable runtime to be ready
120
- await document .querySelector (' ojs-provider' ).whenDefined ();
121
- const runtime = document .querySelector (' ojs-provider' ).value ;
122
- const cats = await runtime .value (' cats' );
123
-
124
- const wrapper = document .querySelector (' .carousel-wrapper' );
125
- cats .forEach (cat => {
126
- const img = document .createElement (' img' );
127
- img .src = cat .url ;
128
- img .alt = ' Cat image' ;
129
- wrapper .appendChild (img);
130
- });
131
-
132
- let currentIndex = 0 ;
133
- const totalImages = cats .length ;
134
-
135
- function updateCarousel () {
136
- wrapper .style .transform = ` translateX(-${ currentIndex * 100 } %)` ;
137
- }
138
-
139
- document .querySelector (' .next' ).addEventListener (' click' , () => {
140
- currentIndex = (currentIndex + 1 ) % totalImages;
141
- updateCarousel ();
142
- });
143
-
144
- document .querySelector (' .prev' ).addEventListener (' click' , () => {
145
- currentIndex = (currentIndex - 1 + totalImages) % totalImages;
146
- updateCarousel ();
147
- });
148
- } catch (error) {
149
- console .error (' Error loading cat data:' , error);
150
- }
151
- });
152
- </script >
153
-
154
- :::
155
-
0 commit comments