Amal_ks
Content Type
Profiles
Forums
Store
Blog
Product
Showcase
FAQ
Downloads
Posts posted by Amal_ks
-
-
Im using Nextjs 14 , is this the correct way of importing gsap for page performance , or any other suggestion ?please evaluate the code , for improvementsuseGSAP(async (context) => {const gsap = (await (import('gsap'))).defaultconst ScrollTrigger = (await (import('gsap/dist/ScrollTrigger'))).defaultconst CustomEase = (await (import('gsap/dist/CustomEase'))).defaultgsap.registerPlugin(ScrollTrigger);gsap.registerPlugin(CustomEase);gsap.config({nullTargetWarn: false,force3D : true,});let mm = gsap.matchMedia();mm.add("(min-width : 992px)", () => {const magBtn =context.selector(".magnetic-btn");//magnetic-btnmagBtn?.forEach((btn) => {btn.addEventListener('mousemove', (e) => {let bounding = btn.getBoundingClientRect();let magnetsStrength = 30;gsap.to(btn, {x: (((e.clientX - bounding.left) / btn.offsetWidth) - 0.5) * magnetsStrength,y: (((e.clientY - bounding.top) / btn.offsetHeight) - 0.5) * magnetsStrength,rotate: "0.001deg",ease: "Power4.easeOut",duration: 1.5,});})btn.addEventListener('mouseleave', function (event) {gsap.to(btn, {x: 0,y: 0,ease: "Elastic.easeOut",duration: 1.5,});});})})}, { scope: Animcontainer });
-
Thanks
14 minutes ago, Rodrigo said:Hi @Amal_ks and welcome to the GSAP Forums!
This doesn't look right to me:
return { Animcontainer };
The return statement in a React functional component should be JSX right now you're returning a ref and that's why you're getting a scope warning, because nowhere in your code that ref is being set to an actual DOM node.
Hopefully this clear things up. If you keep having issues then create a minimal demo that clearly illustrates the problem.
Happy Tweening!
Thanks , is this an issue... does this affect the performnce ?
-
<section ref={animContainer}><div className="box"></div><div className="box2"></div><div className="box3"></div></section>useGSAP((context) => {let element = context.selector('.box');} , {scope:animContainer})is this the right way to select the element ,when i do this , " Invalid scope " is showing on console.
-
import { useRef } from "react";const useDeskAnim = () => {const Animcontainer = useRef();useGSAP(async (context) => {const gsap = (await (import('gsap'))).defaultconst ScrollTrigger = (await (import('gsap/dist/ScrollTrigger'))).defaultconst CustomEase = (await (import('gsap/dist/CustomEase'))).defaultgsap.registerPlugin(ScrollTrigger);gsap.registerPlugin(CustomEase);gsap.config({nullTargetWarn: false,force3D: true,});let mm = gsap.matchMedia();mm.add("(min-width : 992px)", () => {let easing = CustomEase.create("custom", "0.215, 0.61, 0.355, 1");const fadeElement = context.selector('.fade-elm');//common-fade-upfadeElement ?ScrollTrigger.batch((".fade-elm"), {onEnter: (batch) =>gsap.to(batch,{// opacity: 1,autoAlpha: 1,y: 0,force3D: true,stagger: 0.1,duration: .6,ease: easing,delay: 0,// onComplete: () => context.revert(),}),start: "top 98%",end: "top 90%",// markers: { startColor: "black", endColor: "blue" },}) : ""})}, { scope: Animcontainer });return { Animcontainer };};export default useDeskAnim;" const fadeElement = context.selector('.fade-elm'); => is showing invalid scope ? "
Dynamic Import
in GSAP
Posted
ok, Thanks
i just want to know that , i have imported gsap in correct way ??