Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
lucrampro

GSAP with mouseover JQuery

Recommended Posts

Hey, everybody!
I have a problem I try to make a round grow if a mouse passes over but the animation is done directly I don't understand, doesn't GSAP work with Jquery?

 

if ($(".scale").mouseover) {

    TweenMax.to(".scale", 1, {
        css: {
            scale: 2,
            backgroundColor: "#343434"
        }

    });

} else {

    TweenMax.to(".scale", 1, {
        css: {
            scale: 1
        }
    });

}

please help me :)

Link to comment
Share on other sites

Your if statement will always be true. You might want to go check up on how jQuery hover works, and then make a demo if you can't get it working.

https://api.jquery.com/hover/

Link to comment
Share on other sites

Hi @lucrampro,

 

GSAP certainly works well with jQuery ... but it looks like you're using jQuery incorrectly (if I understand what you want to accomplish). It looks like you want to respond to mouseenter and mouseleave ... simply a hover event.

 

$(".scale").hover(
  
  function(){
    TweenMax.to( $(this), 1, {
        css: {
            scale: 2,
            backgroundColor: "#343434"
        }

    });
  },
  
  function(){
    TweenMax.to( $(this), 1, {
        css: {
            scale: 1
        }

    });
  }
 
 );

 

EDIT: Sorry @OSUblake, didn't see that we were responding at the same time :)

  • Like 2
Link to comment
Share on other sites

5 minutes ago, lucrampro said:

why always true?

 

if ($(".scale").mouseover) { ...

 

will always return true because it will return all matching element properties ( i.e not return FALSE )

  • Like 1
Link to comment
Share on other sites

2 minutes ago, lucrampro said:

why always true?

 

Because you're just checking if there something called "mouseover" on a jQuery object, which there is. It's called a truthy value.

https://developer.mozilla.org/en-US/docs/Glossary/Truthy

 

// Try it
console.log(Boolean($(".scale").mouseover));

 

 

  • Like 4
Link to comment
Share on other sites

I understood why I did not succeed thank you for your help!

 

ps: sorry for my bad english because i'm french

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.
×