Closed dob9601 closed 2 years ago
The reason this looks different on mobile screens is because speed
is only an abstraction for setting translateY
and each increment of speed by 1 will increase the translate effect by 10px -- but pixels aren't responsive and the value will remain consistent not matter the width of the banner.
Instead try using translateY
directly with values as %
, for example translateY: [-50%, 50%]
, this way the effect scales based on the width of the banner.
I can mock it up if it helps.
Thank you! Managed to get it working based off of this information. I've linked the repository in question to assist any future travellers that head this way: https://github.com/dob9601/dob9601.github.io/ (https://danielobr.ie/) and below is the final code:
import {ParallaxBanner} from "react-scroll-parallax";
import "./ParallaxMountains.css"
import MountainImage0 from "./parallax-mountains-layers/0.png";
import MountainImage1 from "./parallax-mountains-layers/1.png";
import MountainImage2 from "./parallax-mountains-layers/2.png";
import MountainImage3 from "./parallax-mountains-layers/3.png";
export function ParallaxMountains() {
return (
<>
<ParallaxBanner
className="ParallaxMountains"
layers={[
{children: <h1 className="Header">About Me | Daniel O'Brien</h1>, className: "HeaderBox", translateY: ["-60%", "60%"]},
{image: MountainImage0, className: "Mountain", expanded: false, translateY: ["-100%", "100%"]},
{image: MountainImage1, className: "Mountain", expanded: false, translateY: ["-80%", "80%"]},
{image: MountainImage2, className: "Mountain", expanded: false, translateY: ["-60%", "60%"]},
{image: MountainImage3, className: "Mountain", expanded: false},
]}
/>
</>
)
}
Great thanks. Would you mind if I used your art as an example of this responsive behavior in the documentation?
Go for it!
If possible, some level of attribution might be nice - just so that people don't end up thinking I've directly taken the example from the docs :)
absolutely, if I end up using it I will attribute and tag you 🙇🏻
Trouble With Implementation
When viewing parallax on smaller displays (such as mobile phones) the initial positions of the parallax layers mean that most of them are already off-screen, viewable here: https://gifted-elion-c1f0f2.netlify.app/
Parallax component: