Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove isInit check to allow setBoundingClientRect intermittently set boundingClientRect #127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-parallax-js",
"version": "6.0.1",
"name": "@gaborottlik/simple-parallax-js",
"version": "6.0.2",
"description": "simpleParallax.js is a lightweight and easy-to-use JS library that adds parallax animations to any image.",
"homepage": "https://simpleparallax.com/",
"main": "dist/react/simpleParallax.umd.js",
Expand Down
29 changes: 14 additions & 15 deletions src/react/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import AnimationManager from "./AnimationManager";
import useGetImageHeight from "./hooks/useGetImageHeight";
import useGetTransitionValue from "./hooks/useGetTransitionValue";
Expand Down Expand Up @@ -49,9 +49,6 @@ const SimpleParallax: React.FunctionComponent<SimpleParallaxProps> = ({
if (boundingClientRect) {
setBoundingClientRect(boundingClientRect);
}
if (!isInit) {
setIsInit(true);
}
setViewportTop(window.scrollY);
}
}, [viewportTop, isVisible, imageRef]);
Expand All @@ -76,17 +73,19 @@ const SimpleParallax: React.FunctionComponent<SimpleParallaxProps> = ({
};
}, [updateParallax]);

const clonedChild = React.isValidElement(children)
? React.cloneElement(children as React.ReactElement, {
style: {
...((children as React.ReactElement).props.style ?? {}),
transform: transformCSS,
willChange: "transform",
transition: transitionCSS,
},
ref: imageRef,
})
: null;
const clonedChild = useMemo(() => {
return React.isValidElement(children)
? React.cloneElement(children as React.ReactElement, {
style: {
...((children as React.ReactElement).props.style ?? {}),
transform: transformCSS,
willChange: "transform",
transition: transitionCSS,
},
ref: imageRef,
})
: null;
}, [children, (children as React.ReactElement).props.style, transformCSS, transitionCSS])

return (
<div
Expand Down
Loading