Jump to content
Search Community

Is it possible to set a dataset attribute?

Robert Wildling test
Moderator Tag

Recommended Posts

Hi, dear GSAP afficionados!

 

I was trying to find a way to set the value of a dataset attribute? But so far I failed, because I do not know, how to set something that does not have a key-value pair.

 

The idea is to get the height of an element before hiding it. That height value should be saved to a `data-original-height` attribute, so that at a later point, another animation can pick up that value and create an exact "show" animation tweening to  its exact height. (Of course the has to be updated on media queries and probably window.resize...)

 

Thank you!

Link to comment
Share on other sites

Hey Robert. I think you're going about this the wrong way.

 

I'd just animate to a height of 0 and later animate to a height of "auto" (GSAP supports that natively). An example:

See the Pen vYLJmXY?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Though it is definitely possible to access and/or animate a data attribute using the attr plugin:

See the Pen ZEQJKpx?editors=0010 by GreenSock (@GreenSock) on CodePen

  • Like 1
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...