Comments (2)
To solve the task, we need to add touch event listeners to the two Vue components ReaderHorizontal.vue
and ChapterPageModeSingle.vue
. These listeners will detect a pinch gesture, which is commonly used for zooming in mobile devices.
In the ReaderHorizontal.vue
component, touch event listeners are already implemented. We need to enhance the onTouchMove
method to detect a pinch gesture. This can be done by tracking the distance between two touch points. If the distance increases, it's a zoom-in gesture, and if it decreases, it's a zoom-out gesture. Here's the code snippet:
let initialDistance = null;
function onTouchMove(event) {
if (event.touches.length === 2) {
const touch1 = event.touches[0];
const touch2 = event.touches[1];
const distance = Math.hypot(
touch1.clientX - touch2.clientX,
touch1.clientY - touch2.clientY
);
if (initialDistance === null) {
initialDistance = distance;
} else {
if (distance > initialDistance) {
// Zoom in
} else if (distance < initialDistance) {
// Zoom out
}
initialDistance = distance;
}
} else {
initialDistance = null;
}
// Existing code...
}
In the ChapterPageModeSingle.vue
component, we need to add touch event listeners for touchstart
, touchmove
, and touchend
. In the touchstart
event, we get the initial touch position and the initial zoom level. In the touchmove
event, we calculate the distance between the initial touch position and the current touch position, and adjust the zoom level accordingly. In the touchend
event, we reset the initial touch position and the initial zoom level. Here's the code snippet:
let touchStart = null;
let zoomStart = null;
function onTouchStart(event) {
touchStart = {
x: event.touches[0].clientX,
y: event.touches[0].clientY
};
zoomStart = zoom.value;
}
function onTouchMove(event) {
if (!touchStart || zoomStart === null) return;
const diffX = event.touches[0].clientX - touchStart.x;
const diffY = event.touches[0].clientY - touchStart.y;
const distance = Math.sqrt(diffX * diffX + diffY * diffY);
zoom.value = zoomStart + distance / 10; // Adjust this formula as needed
}
function onTouchEnd() {
touchStart = null;
zoomStart = null;
}
useEventListener(window, "touchstart", onTouchStart);
useEventListener(window, "touchmove", onTouchMove);
useEventListener(window, "touchend", onTouchEnd);
Please note that these are basic implementations and might need adjustments based on your specific requirements. For a more complete implementation, you might want to use a library that provides pinch-to-zoom functionality, or use the GestureEvent
interface if it's available in your target browsers.
Changes on src/components/truyen-tranh/readers/ReaderHorizontal.vue
The file src/components/truyen-tranh/readers/ReaderHorizontal.vue
already has touch event listeners implemented. The touch events are handled by the methods onTouchStart
, onTouchMove
, and onTouchEnd
.
To implement zoom behavior, you need to detect a pinch gesture. This can be done by tracking the distance between two touch points. When the distance increases, it's a zoom-in gesture. When the distance decreases, it's a zoom-out gesture.
You can add this logic in the onTouchMove
method. Here's a simple example of how you can do it:
let initialDistance = null;
function onTouchMove(event) {
if (event.touches.length === 2) {
const touch1 = event.touches[0];
const touch2 = event.touches[1];
const distance = Math.hypot(
touch1.clientX - touch2.clientX,
touch1.clientY - touch2.clientY
);
if (initialDistance === null) {
initialDistance = distance;
} else {
if (distance > initialDistance) {
// Zoom in
} else if (distance < initialDistance) {
// Zoom out
}
initialDistance = distance;
}
} else {
initialDistance = null;
}
// Existing code...
}
This is a basic implementation and might need adjustments based on your specific requirements. For example, you might want to add a threshold for the distance change to avoid accidental zooms. Also, you need to implement the actual zooming logic in the // Zoom in
and // Zoom out
comments.
Changes on src/components/truyen-tranh/readers/__components__/ChapterPageModeSingle.vue
This Vue component already has mouse event listeners for mousedown
, mousemove
, and mouseup
. To add touch events, you can add event listeners for touchstart
, touchmove
, and touchend
.
In the touchstart
event, you can get the initial touch position and the initial zoom level. In the touchmove
event, you can calculate the distance between the initial touch position and the current touch position, and adjust the zoom level accordingly. In the touchend
event, you can reset the initial touch position and the initial zoom level.
Here is a rough example of how you can implement this:
let touchStart = null;
let zoomStart = null;
function onTouchStart(event) {
touchStart = {
x: event.touches[0].clientX,
y: event.touches[0].clientY
};
zoomStart = zoom.value;
}
function onTouchMove(event) {
if (!touchStart || zoomStart === null) return;
const diffX = event.touches[0].clientX - touchStart.x;
const diffY = event.touches[0].clientY - touchStart.y;
const distance = Math.sqrt(diffX * diffX + diffY * diffY);
zoom.value = zoomStart + distance / 10; // Adjust this formula as needed
}
function onTouchEnd() {
touchStart = null;
zoomStart = null;
}
useEventListener(window, "touchstart", onTouchStart);
useEventListener(window, "touchmove", onTouchMove);
useEventListener(window, "touchend", onTouchEnd);
Please note that this is a very basic implementation of pinch-to-zoom. It does not take into account the direction of the pinch (in or out), and it does not handle multi-touch events. For a more complete implementation, you might want to use a library that provides pinch-to-zoom functionality, or use the GestureEvent
interface if it's available in your target browsers.
Current plan usage: 88.50%
Have feedback or need help?
from raiku-app.
from raiku-app.
Related Issues (20)
- Move gtag to firebase analytics HOT 1
- Button has lost its main color HOT 1
- Reader mode right to left wrong sort HOT 1
- Title tab not change if change chap in route `/comic/:comic/chap-:chap` HOT 1
- Chaos occurs during click events in route `/comic/:comic/chap-:chap` HOT 1
- Stores reading progress directly HOT 2
- Auto detect mode reader HOT 1
- Text full wrap in custom button HOT 1
- Fix multiple notification update plugin HOT 3
- upgrade UI plugin store HOT 2
- use tiny name chap in reader HOT 1
- show error network offline HOT 1
- fix favicon small HOT 1
- Offline ready interface HOT 1
- Proxy manager HOT 3
- Not show cause on install plugin not support HOT 1
- [vite] Internal server error HOT 3
- [plugin:vite:import-analysis] Failed to resolve import "raiku-pgs/thread" from "src\stores\plugin.ts". Does the file exist? HOT 2
- Float button no reactive if change state route HOT 1
- Auto check plugin update HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raiku-app.