Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 1.45 KB

03-rotate-an-element-based-on-previous-values-with-greensock.md

File metadata and controls

40 lines (33 loc) · 1.45 KB

Rotate an Element Based on Previous Values with Greensock

📹 Video

Create a box in index.html.

  • div with id="box"

Use gsap to style box.

  • use TweenMax.set() - syntax
TweenMax.set("selectedElement", {properties})

To rotate the box

  1. Use TweenMax.to() inside the eventListener callback function.
document.addEventListener('click', event => {
    TweenMax.to("#box", 0.5, {
        rotation: 30
    })
})
  • Expected behavior will be that a 'click' anywhere on the document will set off an animation on the div with id="box" ("#box") to change it's 'rotation' to 30 degrees.
  • Additional clicks will appear to have no effect since the rotation is already at 30 degrees.
  1. To rotate on additional clicks change,
rotation: 30

to

rotation: "+=30"
  • This will add 30 degrees to the current rotation value and animate the change to that new rotation value.
  • Now additional clicks will continue to rotate the #box.

📹 Go to Previous Lesson 📹 Go to Next Lesson