-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
52 lines (47 loc) · 1.72 KB
/
index.html
File metadata and controls
52 lines (47 loc) · 1.72 KB
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
<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
html, body { height: 100%; margin: 0; }
/* Tam pencere kapla */
#wrap { position: fixed; inset: 0; }
#rive { width: 100%; height: 100%; display: block; }
</style>
<div id="wrap"><canvas id="rive"></canvas></div>
<script src="https://unpkg.com/@rive-app/canvas@2"></script>
<script>
const canvas = document.getElementById('rive');
let riveInstance;
// Canvas'ı cihaz DPR'ına göre boyutlandır
function sizeCanvasToDisplay() {
const dpr = Math.max(1, window.devicePixelRatio || 1);
// CSS boyutu (px)
const cssW = canvas.clientWidth;
const cssH = canvas.clientHeight;
// Backing store boyutu
canvas.width = Math.round(cssW * dpr);
canvas.height = Math.round(cssH * dpr);
// Rive’a çizim yüzeyinin değiştiğini söyle
if (riveInstance && typeof riveInstance.resizeDrawingSurfaceToCanvas === 'function') {
riveInstance.resizeDrawingSurfaceToCanvas();
}
}
// İlk kurulum
riveInstance = new rive.Rive({
src: "./assets/animation.riv",
canvas,
autoplay: true,
artboard: "MainScreen",
stateMachines: ["State Machine 1"],
// Görüntüyü güzelce yaymak için
layout: new rive.Layout({ fit: rive.Fit.COVER, alignment: rive.Alignment.CENTER }),
onLoad: () => {
sizeCanvasToDisplay();
riveInstance.play();
}
});
// Pencere yeniden boyutlandığında güncelle
window.addEventListener('resize', sizeCanvasToDisplay);
// Zoom/DPR değişiklikleri için
window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`)
.addEventListener?.('change', sizeCanvasToDisplay);
</script>