Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h2>GSAP animate using relative values for rotation <strong>+=</strong> and <strong>-=</strong></h2>

<div id="box">
  <div class="box">
    <div class="side1 front">1</div>
    <div class="side2 back">2</div>
    <div class="side3 right"><div>3</div></div>
    <div class="side4 left"><div>4</div></div>
    <div class="side5 top">5</div>
    <div class="side6 bottom">6</div>
  </div>
</div>

<button id="button2">rotate box rotateZ 360deg</button> <button id="button1">rotate box rotateZ -360deg</button> <button id="button4">rotate box rotateZ 180deg</button> <button id="button3">rotate box rotateZ -180deg</button>  <br><br>
In GSAP CSS rotate syntax:<br>
<b>rotationX</b> = rotateX<br>
<b>rotationY</b> = rotateY<br>
<b>rotation</b> = rotateZ<br><br>
              
            
!

CSS

              
                body {
  background-color:#444;
  color:#FFF;
}

h2{
  color:#FFF;
}

a{
  color:#F7E309;
}

button{
  font-weight:bold
}

#box {
  width:100px;
  margin:30px;
  /*-webkit-perspective: 800px;
  -moz-perspective: 800px;
  -o-perspective: 800px;
   perspective: 800px;*/
}

.box {
	width: 100px;
	height: 100px;
	margin: 30px auto;
	position: relative;
	/*-webkit-transform-style: preserve-3d;
	-moz-transform-style: preserve-3d;
	-ms-transform-style: preserve-3d;
	transform-style: preserve-3d;*/
}

.box div {
	position: absolute;
text-align:center;
	left: 0;
	top: 0;
line-height:100px;
font-weight:bold;
font-size:40px;
	width: 100px;
	height: 100px;
color:#111;
/*transform-origin: 50% 50% -50px;*/
border: 1px solid #666;
}

.box .side3 div {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
  overflow: hidden;
  background: hsla(120, 100%, 50%, 0.8);
}

.box .side4 div {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
  overflow: hidden;
  background: hsla(180, 100%, 50%, 0.8);
}

.box div span {
  display:block;
  position:relative;
  top:22%;
  font-size:42px;
  font-weight:bold;
}

.box .side1 {
  background: hsla(0, 100%, 50%, 0.8);
  /*-webkit-animation: animate1 12s infinite linear;
  animation: animate1 12s infinite linear;*/
}

.box .side2 {
  background: hsla(60, 100%, 50%, 0.8);
  /*-webkit-animation: animate2 12s infinite linear;
  animation: animate2 12s infinite linear;*/
}

.box .side3 {
  background: hsla(120, 100%, 50%, 0.8);
  /*-webkit-animation: animate3 12s infinite linear;
  animation: animate3 12s infinite linear;*/
}

.box .side4 {
  background: hsla(180, 100%, 50%, 0.8);
  /*-webkit-animation: animate4 12s infinite linear;
  animation: animate4 12s infinite linear;*/
}

.box .side5 {
  background: hsla(240, 100%, 50%, 0.8);
  /*-webkit-animation: animate5 12s infinite linear;
  animation: animate5 12s infinite linear;*/
}

.box .side6 {
  background: hsla(300, 100%, 50%, 0.8);
  /*animation: animate6 12s infinite linear;
  -webkit-animation: animate6 12s infinite linear;*/
}

/* for Chrome and Chrome */
/*@-webkit-keyframes animate1 {
0% {
-webkit-transform: perspective(600px) rotateX(0deg) rotateY(90deg) rotateZ(0deg);
}
100% {
-webkit-transform: perspective(600px) rotateX(360deg) rotateY(450deg) rotateZ(0deg);
}
}
@-webkit-keyframes animate2 {
0% {
-webkit-transform:perspective(600px) rotateX(0deg) rotateY(270deg) rotateZ(0deg);
}
100% {
-webkit-transform:perspective(600px) rotateX(360deg) rotateY(630deg) rotateZ(0deg);
}
}
@-webkit-keyframes animate3 {
0% {
-webkit-transform:perspective(600px) rotateX(90deg) rotateY(0deg) rotateZ(0deg);
}
100% {
-webkit-transform:perspective(600px) rotateX(450deg) rotateY(0deg) rotateZ(-360deg);
}
}
@-webkit-keyframes animate4 {
0% {
-webkit-transform:perspective(600px) rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
}
100% {
-webkit-transform:perspective(600px) rotateX(270deg) rotateY(0deg) rotateZ(360deg);
}
}
@-webkit-keyframes animate5 {
0% {
-webkit-transform:perspective(600px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
}
100% {
-webkit-transform:perspective(600px) rotateX(360deg) rotateY(360deg) rotateZ(0deg);
}
}
@-webkit-keyframes animate6 {
0% {
-webkit-transform:perspective(600px) rotateX(0deg) rotateY(180deg) rotateZ(0deg);
}
100% {
-webkit-transform:perspective(600px) rotateX(360deg) rotateY(540deg) rotateZ(0deg);
}
}*/

/* for Firefox and IE10 */
/*@keyframes animate1 {
0% {
transform: perspective(600px) rotateX(0deg) rotateY(90deg) rotateZ(0deg);
}
100% {
transform: perspective(600px) rotateX(360deg) rotateY(450deg) rotateZ(0deg);
}
}
@keyframes animate2 {
0% {
transform:perspective(600px) rotateX(0deg) rotateY(270deg) rotateZ(0deg);
}
100% {
transform:perspective(600px) rotateX(360deg) rotateY(630deg) rotateZ(0deg);
}
}
@keyframes animate3 {
0% {
transform:perspective(600px) rotateX(90deg) rotateY(0deg) rotateZ(0deg);
}
100% {
transform:perspective(600px) rotateX(450deg) rotateY(0deg) rotateZ(-360deg);
}
}
@keyframes animate4 {
0% {
transform:perspective(600px) rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
}
100% {
transform:perspective(600px) rotateX(270deg) rotateY(0deg) rotateZ(360deg);
}
}
@keyframes animate5 {
0% {
transform:perspective(600px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
}
100% {
transform:perspective(600px) rotateX(360deg) rotateY(360deg) rotateZ(0deg);
}
}
@keyframes animate6 {
0% {
transform:perspective(600px) rotateX(0deg) rotateY(180deg) rotateZ(0deg);
}
100% {
transform:perspective(600px) rotateX(360deg) rotateY(540deg) rotateZ(0deg);
}
}*/
              
            
!

JS

              
                $(function() {

  TweenMax.set($("#box"), {
    css: {
      perspective: "800px"
    }
  });
  TweenMax.set($(".box"), {
    css: {
      transformStyle: "preserve-3d"
    }
  });
  TweenMax.set($(".box div"), {
    css: {
      transformOrigin: "50% 50% -50px",
      transformPerspective: "800px"
    }
  });

  var tl = new TimelineMax({
    paused: true,
    repeat: -1//,
    //yoyo: true
  });

  // side 1
  tl.fromTo($(".front"), 5, {
    immediateRender: false,
    rotationX: "0deg",
    rotationY: "90deg",
    rotationZ: "0deg"
  }, {
    rotationX: "0deg",
    rotationY: "450deg",
    rotationZ: "0deg",
    ease: Linear.easeNone
  }, "cube");

  // side 2
  tl.fromTo($(".back"), 5, {
    immediateRender: false,
    rotationX: "0deg",
    rotationY: "270deg",
    rotationZ: "0deg"
  }, {
    rotationX: "0deg",
    rotationY: "630deg",
    rotationZ: "0deg",
    ease: Linear.easeNone
  }, "cube");

  // side 3
  tl.fromTo($(".right"), 5, {
    immediateRender: false,
    rotationX: "90deg",
    rotationY: "0deg",
    rotationZ: "0deg"
  }, {
    rotationX: "90deg",
    rotationY: "360deg",
    rotationZ: "0deg",
    ease: Linear.easeNone
  }, "cube");

  // side 4
  tl.fromTo($(".left"), 5, {
    immediateRender: false,
    rotationX: "-90deg",
    rotationY: "0deg",
    rotationZ: "0deg"
  }, {
    rotationX: "-90deg",
    rotationY: "360deg",
    rotationZ: "0deg",
    ease: Linear.easeNone
  }, "cube");

  // side 5
  tl.fromTo($(".top"), 5, {
    immediateRender: false,
    rotationX: "0deg",
    rotationY: "0deg",
    rotationZ: "0deg"
  }, {
    rotationX: "0deg",
    rotationY: "360deg",
    rotationZ: "0deg",
    ease: Linear.easeNone
  }, "cube");

  // side 6
  tl.fromTo($(".bottom"), 5, {
    immediateRender: false,
    rotationX: "0deg",
    rotationY: "180deg",
    rotationZ: "0deg"
  }, {
    rotationX: "0deg",
    rotationY: "540deg",
    rotationZ: "0deg",
    ease: Linear.easeNone
  }, "cube");

  tl.progress(1).progress(0);
  tl.play(0);
  
  // buttons triggering relative values += and -=
   $(document).on("click", "#button1", function() {

    TweenMax.to("#box", 2, {
      rotation: "+=360"
    });

    return false;

  }).on("click", "#button2", function() {

    TweenMax.to("#box", 2, {
      rotation: "-=360"
    });

    return false;

  }).on("click", "#button3", function() {

    TweenMax.to("#box", 2, {
      rotation: "+=180"
    });

    return false;

  }).on("click", "#button4", function() {

    TweenMax.to("#box", 2, {
      rotation: "-=180"
    });

    return false;

  })

});
              
            
!
999px

Console