Jump to content
Search Community

Swinging sign?

Climber test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I'm trying to make a sign image look like it's swinging back and forth towards the user with the correct perspective. For example where the sign would get wider at the bottom as it swings closer to the camera and then narrower as it swings back. Can something like this be achieved just with skewing or is there some other kind of perspective property? I guess this is as much a regular css question as it is a tweenmax one. Any tips would be greatly appreciated!

Link to comment
Share on other sites

You would definitely want to tap into the 3D capabilities of CSS3 for this.


Here are 2 demos that show GSAP working with CSS3:




Those demos use Adobe Edge Animate for the general layout of the assets which certainly isn't necessary.


This thread here will bring you up to speed on using an onUpdate callback to apply 3D transform settings manually to an object as a tween runs:




As that thread notes, 3D transform support is not currently baked into the CSSPlugin but its in the works. At some point in the future doing a 3D spin, swing or flip will be very easy and intuitive.

  • Like 1
Link to comment
Share on other sites

Thanks so much for the help. This got me on the right track. Here's the code I ended up using if it helps anyone:


$('.swing img').mouseenter(function(event)
var sign = event.currentTarget;
sign.rotationX = 0;
TweenMax.to(sign, 0.2, { rotationX:-20, ease:Power1.easeOut, onUpdate:onUpdate, onUpdateParams:["{self}"]});
TweenMax.to(sign, 0.4, { rotationX:8, ease:Power1.easeInOut, onUpdate:onUpdate, onUpdateParams:["{self}"], delay:0.2 });
TweenMax.to(sign, 3, { rotationX:0, ease:Elastic.easeOut, onUpdate:onUpdate, onUpdateParams:["{self}"], delay:0.6 });
function onUpdate(tween)
var target = tween.target;
target.style.webkitTransform = target.style.transform = target.style.msTransform = target.style.MozTransform = 'rotateX('+(target.rotationX)+'deg)';


.swing {
-moz-perspective: 300px;
-ms-perspective: 300px;
perspective: 300px;
.swing img {
-webkit-transform-origin: 50% 0%;
-moz-transform-origin: 50% 0%;
-ms-transform-origin: 50% 0%;
-transform-origin: 50% 0%;

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Hi and welcome to the forums,


You can see it in action here:



But since the css plugin supports css3 3D transforms all that workaround code is no longer necessary, you can achieve that with just a few lines of code and without including all the vendors prefix (the engine does it for you). It would be something like this:


var img1 = $("img#img1"),
    tl1 = new TimelineMax({paused:true}),
    btn1 = $("button#btn1");

//you set up the default perspective for all elements in the DOM
CSSPlugin.defaultTransformPerspective = 400;

//the point from which the sign is hanging
TweenMax.set(img1, {transformOrigin:'50% 0%'});

    .to(img1, .2, {rotationX:-20})
    .to(img1, .2, {rotationX: 20})
    .to(img1, 2, {rotationX:0, ease:Elastic.easeOut});



You can see it in action here:



Hope this helps,



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