Help - Free Mode - Mobile - Looped #6714
brian-open
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
We're using Swiper on a project that allows the user to scroll between sections/areas. Swiper is set to 'FreeMode' so it allows the user to scroll freely and explore the sections.
https://nationalleprechaunmuseum.flywheelsites.com/story/
We have a rabbit placed on the screen that entices the user to move left or right. When the user scrolls left or right the rabbit will subsequently animate and run in the same direction.
The problem we have is when we view the page on mobile. The running animation does not work well and part of the reason we think is due to the swiper event we are using.
We're using the Swiper 'touchMove' event and once it's triggered we run a check using swiper 'translate' and 'previousTranslate'. This checks where the users previous move position was and then triggers a class on the rabbit to see if it needs to run forwards or backwards. The problem with mobile is that the user has less of the screen to touch so more often than not their touch point is behind their previous touch and this causes the rabbit to direct in the opposite direction when it's moving forward.
Is there a swiper event that could be suggested that would work better to move rabbit moving forwards and backwards in freeMode?
Some help or assistance with this would be greatly appreciated.
Below is an example of the code we are using.
let newTranslate = 0;
let translateState = 0;
let touchOn = false;
var swiper = new Swiper(".mySwiper", {
speed: 600,
// parallax: true,
freeMode: true,
mousewheel: {
// invert: true,
},
function handleMouseMove(event) {
// console.log("Mouse Move");
touchOn = true;
}
setInterval(() => {
if (touchOn) {
if (swiper.previousTranslate === swiper.translate) {
updateSpeedClass("stop");
} else if (swiper.previousTranslate > swiper.translate) {
updateDirection("forwards");
} else {
updateDirection("backwards");
}
}, 200);
function setDirection(args) {
newTranslate = args[0].translate;
}
const swiperNew = document.querySelector(
.mySwiper
);function updateDirection(direction) {
// console.log("direction", direction);
const swiperNew = document.querySelector(
.mySwiper
);}
stopChecker();
function stopChecker() {}
setInterval(() => {
// console.log(swiper);
const previousTranslate = swiper.translate;
}, 1000);
Beta Was this translation helpful? Give feedback.
All reactions