Jump to content
Search Community

can't get marginLeft or margin-left working

cthulhu 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

As a control, the following line in my code works perfectly

var myTween = new TweenLite.to(photo, 1.5, {width:100, height:200, paused:true});

 

but when I change it to any of the following it doesn't work

 

var myTween = new TweenLite.to(photo, 1.5, {marginLeft:'200px', paused:true});

var myTween = new TweenLite.to(photo, 1.5, {marginLeft: 200, paused:true});

 

and the following kicks an error

 

var myTween = new TweenLite.to(photo, 1.5, {margin-left:'200px', paused:true});

var myTween = new TweenLite.to(photo, 1.5, {margin-left: 200, paused:true});

Link to comment
Share on other sites

Yes, when you are tweening css properties like marginLeft, top, backgroundColor etc, you need to use the CSSPlugin. Please consult the JS Getting Started Guide as it covers this in detail.

 

The code you would use would look like this:

 

 

//this works because an <img> element actually has a width attribute
var photo1 = document.getElementById("photo1");
var tween1 = TweenLite.to(photo1, 1.5, {width:400});


//marginLeft is a css property, and thus you need the CSSPlugin
var photo2 = document.getElementById("photo2");
var tween2 = TweenLite.to(photo2, 1.5, {css:{marginLeft:200}});

 

See it in action here: http://jsfiddle.net/geekambassador/nFj66/

 

Also, remember if using TweenLite, you will have to load the CSSPlugin

 

Let us know if you have any other questions

 

Happy Tweening

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