The maskSize animation from Framer Motion is not functioning properly on mobile devices

I have successfully implemented a SVG mask scroll feature in Framer Motion. You can test it out on the sandbox by visiting this link: https://codesandbox.io/p/sandbox/svg-nextjs-masking-vgnhnd. However, there seems to be an issue with its performance on mobile devices. The size of the mask does not increase as expected when viewed on a mobile phone. Has anyone encountered a similar problem before and found a solution? Interestingly, there are websites where this SVG scroll masking works seamlessly on mobile phones.

If you want to see the deployed version, you can visit: but please note that the scroll mask may not work properly on mobile devices.

For reference, here is the link to the sandbox: https://codesandbox.io/p/sandbox/svg-nextjs-masking-vgnhnd.

Below, I have included my code snippets for App.js and style.css files:

import "./styles.css";
import { useScroll, useTransform, motion } from "framer-motion";
import { useRef } from "react";

export default function App() {
  const scene = useRef(null);

  const { scrollYProgress } = useScroll({
    target: scene,
    offset: ["start start", "end end"],
  });

  const imageScale = useTransform(scrollYProgress, [0, 1], ["300px", "3000px"]);

  return (
    <>
      <div style={{ height: "30vh" }}></div>

      <h1>Look at Masking using svg</h1>

      <div className="main" ref={scene}>
        <motion.div className="mask" style={{ maskSize: imageScale }}>
          <img src="/cement-industry.jpg" />
        </motion.div>
      </div>

      <div style={{ height: "100vh" }}></div>
    </>
  );
}

And here's the content of style.css file:


.main {
  height: 250vh;
}

.mask {
  position: sticky;
  top: 0px;
  height: 100vh;
  overflow: hidden;
  -webkit-mask-image: url(/mask-star.svg);
  mask-image: url(/mask-star.svg);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center center;
  mask-position: center center;
}

img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

It appears that the mask size issue persistently affects mobile phone users. Various attempts were made on different phones, resulting in the same outcome. If you have any insights or solutions to share, kindly let me know. Your help is greatly appreciated.

https://i.sstatic.net/weyGP.png

Answer №1

The issue has been successfully resolved by identifying that it was caused by an outdated browser that lacked support for maskSize. To remedy this situation, we made the necessary adjustments by implementing WebkitMaskSize in the style attribute to ensure compatibility with older browsers.

        <motion.div className={styles.mask} style={{ maskSize: imageScale, WebkitMaskSize: imageScale  }}>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Saving the link to the search results for future reference

Procedure: onSearch(searchString) { if (this.props.history) { this.props.history.push( "/details?search=" + encodeURIComponent(searchString) ); } } Explore Bar: <Search onKeyPress={(event) => ...

Exploring the Methods of Page Navigation in React Testing Library (Utilizing Link, a Tag, and history.push)

I am attempting to perform DOM testing on the '/test' URL page. My application utilizes BrowseRouter from react-router-dom. Despite following the user approach, I am trying to manually navigate to the '/test' page using <Link /> ...

Extract the content from the division and set it as the image source

Looking for a way to retrieve the content from a div and insert that into the 'src' parameter of an image. Working on a project where JSON is used to load translation files, preventing me from loading images directly, but I want to at least load ...

NextJS React - WebpackError: Cannot access 'window' before initialization

I'm delving into the world of React and recently completed the "Getting Started" tutorial for NextJs (link), successfully setting up a new project. However, when attempting to import third-party plugins like current-devices or smooth-scrollbar, I enc ...

Guide to Integrating NextAuth(v5) with Next-Intl Middleware in Your Next.js Application

I'm currently developing a Next.js application that relies on NextAuth(v5) for authentication and Next-Intl for internationalization. I am looking to seamlessly integrate these two functionalities. Here's what I have attempted so far: Current Mi ...

The link/routing functionality is not functioning properly post the build creation in the next 13 version

I am currently working on a project in next.js 13, where the only folder I have is named 'explore' and it utilizes dynamic routing. https://i.stack.imgur.com/COnbg.png Within the 'explore' folder, I am mapping over a list and using a ...

When trying to run "npm run build", I encountered a message saying "react-scripts: Permission denied"

Having trouble deploying my Windows 10 Spring-Boot/React app on Ubuntu 18.04. I keep getting a "react-scripts: Permission denied" error despite multiple attempts to resolve it. I'm hoping that someone with expertise in React can identify where I' ...

Unselect all options in Angular's multiple selection feature

Objective: My goal is to ensure that when I invoke the myMethod() function, all options are unselected. Current Issue: Currently, calling myMethod() will only deselect the last option, leaving the others selected if they were previously selected. Possibl ...

Is there a way to change the color of a number's font based on whether it is preceded by a "+" or "-" sign?

I am currently working on a stocks widget and I have a specific requirement. Whenever there is a change in value in the Change or Changeinpercent columns, I need to dynamically set the font color to red for a decrease (-) or green for an increase (+). Her ...

Adjust the size of the embedded iframe to match the dimensions of the containing div

Is there a method to resize the iframe embed code for a vine so that it fits within the boundaries of the enclosing div? The supplied embed code already includes sizing information as shown below: <iframe src="https://vine.co/v/iMJzrThFhDL/embed/simp ...

Control the button's activation status by accepting or unaccepting the two checkbox conditions

In my search through stackoverflow for help on enabling/disabling a button conditionally, I found some assistance but nothing quite matched what I needed. My situation involves two checkbox conditions rather than just one. The button should only be enable ...

Issue in React: Unable to choose options from a dropdown menu once a value attribute has been assigned to the component's state

One issue I encountered with my React component that renders a dropdown menu is that although it successfully re-renders the value when new props are received, it disables the option to select a different value. This behavior occurs because I have set th ...

Adjust the size of flex items to match the size of their container

I'm attempting to design a two-column layout using a flex parent with a height of 100vh. The first column consists of a div containing a heading and a paragraph, while the second column contains a div with an image. I want the flex parent's heigh ...

Demonstrate HTML and CSS integration through the use of the http.get method

In an attempt to create an iframe-like solution, I am using an http.get call to retrieve a site as an object containing HTML and CSS. The issue arises when using <link> tags because the CSS path is obtained from an external source, causing the HTML t ...

The width of my root container does not display at a full 100% in mobile dimensions

After creating a simple React.js project, I set up the folder structure using `npx create-react-app`. Additionally, I added some styling with `* { margin: 0; padding: 0; box-sizing: border-box }`, and specified background colors for the body and #root elem ...

organizing various kinds of data values within an array

Within this array, I have two types of variables - an integer and a string. My goal is to sort the array either alphabetically or by the length of the string. However, it seems that the sorting algorithm is prioritizing the integer over the string. ...

I'm trying to create a horizontal list using ng-repeat but something isn't quite right. Can anyone help me figure out

Feeling a bit lost after staring at this code for what seems like an eternity. I'm trying to create a horizontal list of 2 image thumbnails within a modal using Angular's ng-repeat. Here's the HTML snippet: <div class="modal-body"> ...

Optimizing CSS across various pages and screens sizes with critical importance

My CSS file is in need of optimization for quicker loading times. It contains numerous components utilized across various pages (such as the start page, category pages, and detail pages) on different screen sizes (mobile, tablet, desktop). Manual optimizat ...

Using Jquery to toggle the visibility of div elements with the same structure, but ensuring only one is

Many people have posed this question. I am attempting to create a functionality where a div can expand and collapse using a +/- button. I have 5 divs with class=="expanderContent". When the function below is triggered by a click, all 5 items expand or coll ...

The communication factor that triggers the expansion of the mother element

I've been struggling with this issue for quite some time. Here is the challenge at hand: I am in the process of developing a library to streamline AJAX calls and neatly display error messages directly within a form. The dilemma: Whenever the messag ...