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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <p>The black dot follows the bezier path, hitting the coloured anchor points at the timeline progress as indicated beneath each.<br>
The animation takes 5 seconds, hence 10% occurs at a time of 0.5 seconds, etc.</p>
<svg id="animation" width="400px" height="200px" xmlns=http://www.w3.org/2000/svg viewBox="0 0 200 100">
  <circle cx=0 cy=0 r="2" id="point" />
  <text x="5" y="95" font-size="7" id="tlprogress">Timeline progress: </text>
</svg>
              
            
!

CSS

              
                svg { background-color: #EEE; }
#marker0 { fill: red; }
#marker1 { fill: green; }
#marker2 { fill: blue; }
#marker3 { fill: yellow; }
#marker4 { fill: orange; }
#marker5 { fill: pink; }
#marker6 { fill: purple; }
#marker7 { fill: aqua; }
.highlighted { fill: #fff; }
              
            
!

JS

              
                console.clear();

// Define the bezier parameters
var bezier_duration = 5;
var bezier_curviness = 1;
var bezier_path = [
  {x:10, y:10, progress:0.0},
  {x:30, y:60, progress:0.1},
  {x:90, y:30, progress:0.4},
  {x:170, y:80, progress:0.9},
  {x:190, y:20, progress:1.0}
];

addAnchorMarkers(bezier_path); // Draw the anchor to the screen for visualisation

// createCustomBezierEase is where the magic happens!
var bezier_ease = createCustomBezierEase(bezier_path, bezier_curviness, 'bezier_ease');

// Perform the tween
var tl = new TimelineMax({
  repeat: -1,
  yoyo: true
});
addAnchorHighlights(tl,bezier_duration,bezier_path); // Light up the anchor markers at the correct time
tl.set($('#point'),{x:bezier_path[0].x,y:bezier_path[0].y},0);
tl.to($('#point'), bezier_duration, { bezier: {
  type: 'thru',
  values: bezier_path,
  curviness: bezier_curviness,
  //correlate: 'x,y,progress'
}, ease: bezier_ease, onUpdate: updateProgress }, 0);

function createCustomBezierEase(bezier_path, bezier_curviness, ease_name) {
  var dummy_object = $.extend({},bezier_path[0]);
  var dummy_tween = new TweenMax.to(dummy_object, 1, { bezier: {
    type: 'thru',
    values: bezier_path,
    curviness: bezier_curviness,
    correlate: 'x,y,progress'
  }, ease: Linear.easeNone}, 0);
  
  var progress_subdivs = 20;
  var progress_step = (1/progress_subdivs);
  var custom_ease = 'M0,0';
  for (i=1; i<progress_subdivs; i++) {
    var real_progress = i*progress_step;
    dummy_tween.progress(real_progress);
    var bezier_progress = Math.max(0,Math.min(1,dummy_object.progress));
    bezier_progress = real_progress + (real_progress - bezier_progress);
    custom_ease += ' '+(Math.round(real_progress*100)/100);
    custom_ease += ','+(Math.round(bezier_progress*100)/100);
  }
  custom_ease += ' 1,1'
  //console.log(custom_ease);
  var ease = CustomEase.create(ease_name, custom_ease);
  return ease;
}

// ********** VISUAL CODE ONLY BELOW THIS POINT **********

function updateProgress() {
  $('#tlprogress').html('Timeline progress: '+Math.round(tl.progress()*100)+'%');
}

function addAnchorMarkers(anchors) {
  var svg = document.getElementById("animation");
  var point = document.getElementById("point");
  var svgNS = "http://www.w3.org/2000/svg";
  $.each(anchors,function(i,anchor) {
    var circle = document.createElementNS(svgNS, 'circle');
    circle.setAttributeNS(null, "id", "marker"+i);
    circle.setAttributeNS(null, "cx", anchor.x);
    circle.setAttributeNS(null, "cy", anchor.y);
    circle.setAttributeNS(null, "r", 5);
    svg.insertBefore(circle,point);
    var text = document.createElementNS(svgNS, 'text');
    text.setAttributeNS(null, "x", anchor.x);
    text.setAttributeNS(null, "y", anchor.y+10);
    text.setAttributeNS(null, "font-size", 5);
    text.setAttributeNS(null, "text-anchor", 'middle');
    text.setAttributeNS(null, "alignment-baseline", 'central');
    text.innerHTML = Math.round(anchor.progress*100)+'%';
    svg.insertBefore(text,point);
  });
}

function addAnchorHighlights(tl, duration, anchors) {
  $.each(anchors,function(i,anchor) {
    var progress_before = Math.max(0,Math.min(1,anchor.progress-0.01));
    tl.set($('#marker'+i),{'stroke-width':1,'stroke':'#222'},duration*progress_before);
    var progress_after = Math.max(0,Math.min(1,anchor.progress+0.01));
    tl.set($('#marker'+i),{'stroke-width':0,'stroke':'#222'},duration*progress_after);
  });
}
              
            
!
999px

Console