@@ -23,8 +23,8 @@ const Christmas = () => {
23
23
0.1 ,
24
24
1000
25
25
)
26
- camera . position . set ( 0 , 2 , 6 )
27
- camera . lookAt ( 0 , 0 , 0 )
26
+ camera . position . set ( - 3.23 , 2.98 , 4.06 )
27
+ camera . updateProjectionMatrix ( )
28
28
// 创建渲染器
29
29
const renderer = new THREE . WebGLRenderer ( {
30
30
antialias : true // 抗锯齿
@@ -35,6 +35,8 @@ const Christmas = () => {
35
35
controller . enableDamping = true
36
36
// 设置阻尼系数
37
37
controller . dampingFactor = 0.05 // 数值越小,惯性越大
38
+ controller . target . set ( - 8 , 2 , 0 )
39
+
38
40
function onresize ( ) {
39
41
renderer . setSize (
40
42
canvasDom . current ! . offsetWidth ,
@@ -179,17 +181,19 @@ const Christmas = () => {
179
181
}
180
182
}
181
183
]
182
- let index = useRef ( 0 )
184
+ let [ index , setIndex ] = useState ( 0 )
185
+ let i = 0
183
186
let isAnimate = useRef ( false )
184
187
function onscroll ( e : WheelEvent ) {
185
188
if ( isAnimate . current ) return
186
189
isAnimate . current = true
187
190
if ( e . deltaY > 0 ) {
188
- index . current += 1
189
- if ( index . current > scenes . length ) {
190
- index . current = 0
191
+ i += 1
192
+ if ( i >= scenes . length ) {
193
+ i = 0
191
194
}
192
- scenes [ index . current ] . callback ( )
195
+ setIndex ( i )
196
+ scenes [ i ] . callback ( )
193
197
}
194
198
setTimeout ( ( ) => {
195
199
isAnimate . current = false
@@ -269,12 +273,42 @@ const Christmas = () => {
269
273
}
270
274
} , [ ] )
271
275
return (
272
- < div className = "page-container" >
276
+ < div className = "page-container" style = { { position : 'relative' } } >
273
277
< div
274
278
id = "canvasDom"
275
279
className = { styles . canvasContainer }
276
280
ref = { canvasDom }
277
281
> </ div >
282
+ < div
283
+ className = { [ styles . scenes , index == 0 ? styles . lastScene : '' ] . join (
284
+ ' '
285
+ ) }
286
+ style = { {
287
+ transform : `translate3d(0, ${ - index * 100 } %, 0)`
288
+ } }
289
+ >
290
+ { scenes . map ( ( scene , index ) => {
291
+ return (
292
+ < div
293
+ key = { index }
294
+ style = { {
295
+ width : '100%' ,
296
+ height : '100%'
297
+ } }
298
+ >
299
+ < h1
300
+ style = { {
301
+ padding : '50px 50px' ,
302
+ fontSize : '30px' ,
303
+ color : 'white'
304
+ } }
305
+ >
306
+ { scene . text }
307
+ </ h1 >
308
+ </ div >
309
+ )
310
+ } ) }
311
+ </ div >
278
312
</ div >
279
313
)
280
314
}
0 commit comments