Jump to content
Search Community

TextPlugin and animations don't work on reload/bugg

Gr0x test
Moderator Tag

Recommended Posts

Hello! Im kinda new here and hope someone can help me with this animation bug I have.

 

Textplugin: I want a empty div that writes out "Hello World!", wish it worked first time. Then i randomly press "ctrl + R" in my Chrome, and now it dont work at all.

 

Bouncing mouse: It works when ever it want to work.. So basically when i "yarn start" my project the bounce doesn't work. But when i go in to the component file and edit the code

gsap.to(".HW_context", {duration: 2, text: "Hello World!", ease: "none"});

to this code (below) and save it, i get an error (obviously), removes the "1" from the code "gsap.t1o" and then the mouse start bouncing.. 

gsap.t1o(".HW_context", {duration: 2, text: "Hello World!", ease: "none"});

 

App.js.png

TextPlugin.png

Bounce.png

Link to comment
Share on other sites

Ah ok, textplugin issue is because you've got a fullstop in your class name. 

<div class=".HW_context" id="typewriter"></div

 

You also don't need to 'import' in codepen. I took that line out and the second pen seems to be working fine! Could you maybe explain the issue again for me differently?

  • Like 3
Link to comment
Share on other sites

What do you mean with 'fullstop' ? oh! Yeah, i saw that i had a "." in the Class.. Now it's removed and still doesnt work.. :(

 

What did you change to make the text work?

 

 

oh, okey. But i have to do it in react.. 

The issue is that when i start my project (yarn start) in the terminal, the mouse is still (no animations), but when i manipulate an error in the code (for an instance instead of "gsap.fromTo" i write "gsap.fromT1o" (just to get an error.) Then i remove the "1" in the code and the animation starts to work as long as i dont refresh the page. 

Edited by Gr0x
saw the misspelling in the class
Link to comment
Share on other sites

23 minutes ago, Gr0x said:

The issue is that when i start my project (yarn start) in the terminal, the mouse is still (no animations), but when i manipulate an error in the code (for an instance instead of "gsap.fromTo" i write "gsap.fromT1o" (just to get an error.) Then i remove the "1" in the code and the animation starts to work as long as i dont refresh the page. 


Afraid this sounds like something funny happening in your setup pal.

I don't think I can help here I'm afraid. Your GSAP code is spot on.

  • Like 2
Link to comment
Share on other sites

Hi Blake! 😃

 

I've been sitting with this issue now and been following the: https://edidiongasikpo.com/using-gsap-scrolltrigger-plugin-in-react

But i really cant make it work.. This is the "new" component:

 

import mouse from '../assets/mouse-scroll.svg';
import { useRef, useEffect } from "react";
import gsap from "gsap";
 
function Mouse() {
 
const mouse_bounce = useRef(null);
  useEffect(() => {
    const element = mouse_bounce.current;
    gsap.fromTo(
      element.querySelector("mouse-icon"),
      {
        y: -30,
      },
      {
            duration: 0.7,
            delay: 2,
            y:0,
            ease:"circ.in",
            repeat:-1,
            yoyo:true
        },
    );
  }, []);
 
return (
<div className="mouse-div">
<img ref={mouse_bounceid="mouse-icon" className="mouse-img" src={mousealt="mouse-scroll" />
</div>   
);
}
 
export default Mouse;

 

I really dont have any clue what i can do now to make it work.. I appreciate all the help i can get :)

Link to comment
Share on other sites

Heya, 

The target you're passing to the mouse bounce tween is currently targeting nothing. querySelector needs a valid CSS selector string to find the target.

eg, to target an ID -

 document.querySelector("#mouse-icon")

 

Also, (and this is cool) GSAP uses querySelector under the hood anyway, so you can do away with that method entirely. This....

gsap.fromTo(element.querySelector("mouse-icon")),
 {
  y: -30
 },
 {
  duration: 0.7,
  delay: 2,
  y: 0,
  ease: "circ.in",
  repeat: -1,
  yoyo: true
 }
);


becomes this...

gsap.fromTo("#mouse-icon"),
 {
  y: -30
 },
 {
  duration: 0.7,
  delay: 2,
  y: 0,
  ease: "circ.in",
  repeat: -1,
  yoyo: true
 }
);


You also don't need a fromTo tween as in your example the mouse is animating 'to' it's initial value of 0 anyway. I find that most of the time you can accomplish what you need with either from or to! 

gsap.to("#mouse-icon"),
 {
  duration: 0.7,
  delay: 2,
  y: -30
  ease: "circ.in",
  repeat: -1,
  yoyo: true
 }
);


Hope this helps.
 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...