-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: explain generation of animated slides
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<script setup> | ||
import imageUrl from "../../assets/images/how-it-works.png" | ||
import {ref, onMounted, onUnmounted} from "vue"; | ||
const zoomLevel = ref(1); // Track zoom level | ||
const position = ref({x: 0, y: 0}); // Track image position | ||
const dragging = ref(false); // Track dragging state | ||
const lastMousePosition = ref({x: 0, y: 0}); // Store the last mouse position for calculations | ||
// Handle mouse down to start dragging | ||
const handleMouseDown = (e) => { | ||
dragging.value = true; | ||
console.log(dragging.value) | ||
lastMousePosition.value = {x: e.clientX, y: e.clientY}; | ||
}; | ||
// Handle mouse movement for dragging | ||
const handleMouseMove = (e) => { | ||
if (!dragging.value) return; | ||
const dx = e.clientX - lastMousePosition.value.x; | ||
const dy = e.clientY - lastMousePosition.value.y; | ||
position.value.x += dx; | ||
position.value.y += dy; | ||
lastMousePosition.value = {x: e.clientX, y: e.clientY}; | ||
}; | ||
// Stop dragging on mouse up | ||
const handleMouseUp = () => { | ||
dragging.value = false; | ||
}; | ||
// Handle zooming with the scroll wheel | ||
const handleWheel = (e) => { | ||
const zoomFactor = 0.1; // Adjust zoom factor as needed | ||
if (e.deltaY < 0) { | ||
zoomLevel.value = Math.min(zoomLevel.value + zoomFactor, 2); // Limit max zoom | ||
} else { | ||
zoomLevel.value = Math.max(zoomLevel.value - zoomFactor, 0.8); // Limit min zoom | ||
} | ||
}; | ||
// Attach event listeners | ||
onMounted(() => { | ||
window.addEventListener("mousemove", handleMouseMove); | ||
window.addEventListener("mouseup", handleMouseUp); | ||
window.addEventListener("wheel", handleWheel); | ||
}); | ||
// Cleanup event listeners | ||
onUnmounted(() => { | ||
window.removeEventListener("mousemove", handleMouseMove); | ||
window.removeEventListener("mouseup", handleMouseUp); | ||
window.removeEventListener("wheel", handleWheel); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div | ||
class="relative w-full h-screen overflow-hidden cursor-crosshair" :class="{'cursor-grabbing': dragging}" | ||
@mousedown="handleMouseDown" | ||
> | ||
<!-- Image --> | ||
<img | ||
:src="imageUrl" | ||
alt="Large Image" | ||
:style="{ | ||
transform: `translate(${position.x}px, ${position.y}px) scale(${zoomLevel})` | ||
}" | ||
class="select-none" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
/* Basic styles for better interaction */ | ||
.relative { | ||
user-select: none; /* Prevent selection while dragging */ | ||
} | ||
.select-none { | ||
pointer-events: none; /* Prevent interactions with the image itself */ | ||
} | ||
</style> |