Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div id="wrapper">
  <svg id="charly" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 151 207"  width="150.428" height="206.518">
    <g id="layer1" stroke="#000" stroke-linejoin="round">
      <g id="zaehne" fill="#558d35" stroke-width="2" stroke-dashoffset="1.52" stroke-linecap="square" stroke-linejoin="round">
        <path id="rect3009" d="M580.387 587.28h15.816v19.914h-15.816z" transform="matrix(1.00885 0 0 .88518 -463.3 -386.985)"/>
        <path id="rect3009-4" d="M532.292 587.105h13.934v14.13h-13.934z" transform="matrix(1.00885 0 0 .88518 -463.3 -386.985)"/>
        <path id="rect3009-8" d="M546.156 587.14h15.092v14.382h-15.092z" transform="matrix(1.00885 0 0 .88518 -463.3 -386.985)"/>
        <path id="rect3009-82" d="M560.757 587.356h20.09v23.164h-20.09z" transform="matrix(1.00885 0 0 .88518 -463.3 -386.985)"/>
      </g>
      <path id="mundauf" fill="#f5e021" stroke-width="5" d="M24.52 202.81c1.302-41.545 4.28-83.092-.934-124.64-28.73-2.07-28.05-27.826 1.72-28.986C32.45 2.992 62.116 4.022 97.9 2.507c56.074 1.282 58.652 57.617 38.588 59.13h-23.123 7.302l23.91 55.405-83.804 16.673 36.122 14.95-1.785 55.363" stroke-linecap="round" stroke-linejoin="round"/>
      <path id="mundzu" fill="#f5e021" stroke-width="5" d="M24.52 202.81c1.302-41.545 4.28-83.092-.934-124.64-28.73-2.07-28.05-27.826 1.72-28.986C32.45 2.992 62.116 4.022 97.9 2.507c56.074 1.282 58.652 57.617 38.588 59.13h-23.123 7.302l23.91 70.01-60.42.577H97.54l-2.435 71.804"/>
      <g id="g3023" fill="#e18db8" stroke-dashoffset="1.52" stroke-linecap="square" stroke-linejoin="round">
        <path id="path3766" stroke-width="2.92" d="M103.85 40.468c0 8.327-8.063 15.077-18.01 15.077-9.944 0-18.007-6.75-18.007-15.077S75.896 25.39 85.84 25.39c9.947 0 18.01 6.75 18.01 15.078z"/>
        <path id="path3766-1" stroke-width="2" d="M88.972 39.812c0 1.7-1.648 3.08-3.68 3.08s-3.68-1.38-3.68-3.08c0-1.702 1.648-3.08 3.68-3.08s3.68 1.378 3.68 3.08z"/>
      </g>
    </g>
  </svg>
  <div id="scroll">
   <div id="scrollDistance"></div>
  </div>
  
</div>

<div class="nav">
  <button id="next" class="hidden">next</button>
  <button id="back" class="hidden">back</button>
  <button id="repeat" class="hidden">repeat</button>
  <button id="auto">auto</button>
  <button id="stop">stop</button>

  <button class="playLabelButton hidden one">one</button>
  <button class="playLabelButton hidden two">two</button>
  <button class="playLabelButton hidden three">three</button>
  <button class="playLabelButton hidden four">four</button>
</div>


              
            
!

CSS

              
                body{
  margin: 0;
}
#wrapper{
  position: relative;
  height: 300px;
  width: 600px;
  margin: 20px 0 0 20px;
  background: green;
  overflow: hidden;
}
#charly{
  position: absolute;
  width: 150px;
  height: auto;
  top: 75%;
  left: -20%;
}

#scroll{
  width: 114%;
  height: 100%;
  overflow-y: scroll;
  position: absolute;
}
#scrollDistance{
  width: 100%;
  height: 5000px;
  cursor: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/174563/scroll.png) , pointer;
}

.nav{
  position: relative;
  margin: 10px 0 0 20px;
}
button{
  border: none;
  padding: 6px 10px;
  outline: 0;
  cursor:pointer;
}

button:nth-of-type(4){
  margin-left:20px;
}
button:nth-of-type(6){
  margin-left:20px;
}
.active{
  background:green;
}
              
            
!

JS

              
                TweenLite.set('#mundauf', {autoAlpha:0});
TweenMax.set("#charly", {xPercent:-50, yPercent:-50, autoAlpha:1});


var charly = new TimelineMax({paused:true})
.to('#charly',1.2,{x:250, ease: Bounce.easeOut}, "label1")
.to(".playLabelButton",0, {className:"-=active"},0)
.to(".one",0, {className:"+=active"},0)

.addPause()
.to("#mundzu",0.3, {morphSVG:"#mundauf"},"label2")
.to("#zaehne",0.3, {rotation:-10, transformOrigin:"center top", y:-10},"label2")
.to(".playLabelButton",0, {className:"-=active"},"label2")
.to(".two",0, {className:"+=active"},"label2")

.addPause()
.to('#charly',1,{rotationY:40, transformOrigin:"center", repeat:1,yoyo:true},"label3")
.to("#mundzu",0.3, {morphSVG:"#mundzu"},"label3")
.to("#zaehne",0.3, {rotation:0, transformOrigin:"center top", y:0},"label3")
.to(".playLabelButton",0, {className:"-=active"},"label3")
.to(".three",0, {className:"+=active"},"label3")

.addPause()
.to('#charly',1,{scaleY:1.2, transformOrigin:"bottom"},"label4")
.to('#charly',2,{x:800,scaleY:0.8, y:0,transformOrigin:"bottom"})
.to(".playLabelButton",0, {className:"-=active"},"label4")
.to(".four",0, {className:"+=active"},"label4")
;





$('#next').on('click', function(){
    charly.play();
});
$('#back').on('click', function(){
    charly.reverse();
});
$('#repeat').on('click', function(){
  charly.play( charly.getLabelBefore() );
});

// Timeline TOTAL without pause
var total = new TimelineMax({paused:true,repeat:-1})
.to('#charly',1.2,{x:250, ease: Bounce.easeOut}, "label1")
.to(".playLabelButton",0, {className:"-=active"},0)
.to(".one",0, {className:"+=active"},0)
.to("#mundzu",0.3, {morphSVG:"#mundauf"},"label2")
.to("#zaehne",0.3, {rotation:-10, transformOrigin:"center top", y:-10},"-=0.3")
.to(".playLabelButton",0, {className:"-=active"},"label2")
.to(".two",0, {className:"+=active"},"label2")
.to('#charly',1,{rotationY:40, transformOrigin:"center", repeat:1,yoyo:true},"label3")
.to("#mundzu",0.3, {morphSVG:"#mundzu"},"label3")
.to("#zaehne",0.3, {rotation:0, transformOrigin:"center top", y:0},"label3")
.to(".playLabelButton",0, {className:"-=active"},"label3")
.to(".three",0, {className:"+=active"},"label3")

.to('#charly',1,{scaleY:1.2, transformOrigin:"bottom"},"label4")
.to('#charly',2,{x:800,scaleY:0.8, y:0,transformOrigin:"bottom"})
.to(".playLabelButton",0, {className:"-=active"},"label4")
.to(".four",0, {className:"+=active"},"label4")
;

$('#auto').on('click', function(){
  charly.seek(0).pause();
  total.play();
  TweenLite.set('.hidden',{autoAlpha:0});
  TweenLite.set('#scrollDistance',{height:0, cursor:'pointer'}); //stop scroll function
});
$('#stop').on('click', function(){
  total.seek(0).pause();
  charly.seek(0).pause();
  TweenLite.set('.hidden',{autoAlpha:1});
  TweenLite.set('#scrollDistance',{height:5000, cursor:'url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/174563/scroll.png) , pointer'});
});

$(".playLabelButton").each(function(index, element){
  $(this).click(function(){
    charly.play("label" + (index+1));
    TweenMax.set(".playLabelButton", {className:"-=active"});
    TweenMax.set(this, {className:"+=active"});
  })
})

// === scrolling sync =========================
var lastScrollTop = 0;

$('#scroll').scroll(function(e) {
  var scrollNum = $('#scroll').scrollTop();
  scrollPercent = $('#scroll').scrollTop() / ($('#scrollDistance').height() - $('#scroll').height());
  
var progressBlobs = scrollPercent*1; // slower (= <) or faster and/or change height of 'scrollDistance'
  
  if (scrollNum > lastScrollTop) {  // downscroll
    TweenLite.to(charly, 1, {progress:progressBlobs, ease: Sine.easeOut});
  } else {    //upscroll
    TweenLite.to(charly, 1, {progress:progressBlobs, ease: Sine.easeOut});
  }
  
  lastScrollTop = scrollNum;
  
});


// ==  helper ===============================
function getPauses(charly) {
  var pauses = [],
      a = charly.getChildren(true, true, false),
      i;
  for (i = 0; i < a.length; i++) {
    if (a[i].data === "isPause") {
      pauses.push(a[i]);
    }
  }
  return pauses;
  console.log(pauses);
}


var labels = charly.getLabelsArray();
for (var i = 0; i < labels.length; i++) {
    console.log("label name: " + labels[i].name + ", time: " + labels[i].time);
}
              
            
!
999px

Console