Motion & Games

How to Create a Dot to dot SVG Animation That Syncs to Storyline's Timeline

Learn how to create a stunning "draw-on" SVG animation in Articulate Storyline that perfectly syncs with your timeline. This step-by-step tutorial covers GSAP integration, timeline synchronization, and the SVG stroke-dashoffset technique—even if you're new to JavaScript.

By Nathan Stoker · Published Jan 18, 2026 · Updated Nov 8, 2026 · 12 min read

Download

Watch the video

How to Create a Dot to dot SVG Animation That Syncs to Storyline's Timeline

Have you ever wanted to create that satisfying "line drawing" effect where a shape appears to draw itself on screen? You know the one—it's everywhere in explainer videos and slick presentations. Today, I'm going to show you how to build this effect in Articulate Storyline using JavaScript, GSAP, and SVG magic.

By the end of this tutorial, you'll have an animation that draws a connected polygon between multiple points on your slide, perfectly synchronized with Storyline's timeline. Let's dive in.

Check out the demo and download the file in the header to follow along.

What We're Building

The final result is a polygon shape that:

  • Draws itself progressively as the timeline plays

  • Stays perfectly in sync when scrubbing forward or backward

  • Fills with color once the drawing completes

  • Responds to a custom variable if you need to freeze the animation

Here's a quick preview of what the effect looks like:

  1. Timeline starts → nothing visible

  2. At 0.5 seconds → stroke begins drawing

  3. Over 3 seconds → stroke traces the complete shape

  4. Drawing finishes → shape fills with a smooth fade

Prerequisites

Before we start, make sure you have:

  • Articulate Storyline 360

  • GSAP library (it's included in Articulate Storyline already)

  • Basic understanding of JavaScript variables in Storyline

  • A slide with multiple shape placeholders

Don't worry if the JavaScript looks intimidating—I'll walk you through every piece.

Step 1: Set Up Your Slide with Placeholder Shapes

First, we need anchor points that define where our polygon will draw. In Storyline:

  1. Create a new slide

  2. Add 19 small ovals (or circles) positioned where you want the vertices of your polygon

  3. Arrange them in the order you want the line to connect them

  4. Name each shape descriptively (like "Point1", "Point2", etc.)

Pro Tip: The shapes can be invisible in your final course—they're just reference points. Set their fill to 99% opacity once you've positioned them.

Step 2: Get the Object IDs (Recommended Method)

When working with many objects, use Storyline’s JavaScript trigger object picker to collect IDs safely.

Steps

  1. Add a JavaScript trigger (any event).

  2. Open the object dropdown in the trigger.

  3. Select an oval.

  4. Copy the exposed object ID.

  5. Repeat for all ovals.

  6. Delete the temporary trigger when finished.


Paste the IDs into Your Code

Once collected, add them to an array:

const OVAL_IDS = [
  '5w9p1oRm1rx', '6LmAsv0kF5T', '5ddRPB2TKrk', '5ZR8p16WR7N', '6qo1Hi8eitj',
  '65bxjWnzY0A', '6Sq05MbsCPK', '5rcTZR6tWHp', '6ZhjskvWz68', '6cBNoE7ywlC',
  '5vXsqk4CNrG', '5jXsazaVcmW', '62FQ7yZyEnl', '6eyUZ4RzoID', '5uMZGwt9ZCm',
  '6GWtAJwdOX7', '62bVWhUtFBF', '6OcZpytEsdw', '5v7Zn7lBo2x'
];

Step 3: Understanding the JavaScript Code

Let's break down the complete script into digestible sections.

Configuration Variables

const OVAL_IDS = [
  '5w9p1oRm1rx', '6LmAsv0kF5T', '5ddRPB2TKrk', // ... all your IDs
];
const COLOR = '#C0504D';
const STROKE_WIDTH = 4;
const DRAW_START = 0.5;    // Start drawing at 0.5 seconds
const DRAW_DURATION = 3;   // Drawing takes 3 seconds

This section defines:

  • OVAL_IDS: Your placeholder shape IDs in connection order

  • COLOR: The hex color for both stroke and fill

  • STROKE_WIDTH: How thick the drawing line appears

  • DRAW_START: When the animation begins (in seconds)

  • DRAW_DURATION: How long the draw effect takes

The DOM Helper Function

function dom(id) {
  const element = document.querySelector(`[data-model-id="${id}"]`);
  if (element) return element;
  if (typeof $ !== 'undefined' && $) {
    const jqElement = $(`[data-model-id="${id}"]`)[0];
    if (jqElement) return jqElement;
  }
  return null;
}

This function finds elements by their Storyline data-model-id. It tries the standard querySelector first, then falls back to jQuery (which Storyline includes) if needed.

Waiting for Elements to Load

function waitForAll(ids, callback, tries = 0) {
  const elements = ids.map(dom);
  if (elements.every(Boolean)) return callback(elements);
  
  if (tries >= MAX_TRIES) {
    console.error('Ovals not found after ' + MAX_TRIES + ' tries.');
    return;
  }
  
  setTimeout(() => waitForAll(ids, callback, tries + 1), POLL_MS);
}

Storyline's elements don't all load instantly. This function polls repeatedly until all our shapes are available, then proceeds with the animation setup.

Creating the SVG Overlay

const NS = 'http://www.w3.org/2000/svg';
const svg = document.createElementNS(NS, 'svg');
const fillPath = document.createElementNS(NS, 'path');
const strokePath = document.createElementNS(NS, 'path');

svg.appendChild(fillPath);
svg.appendChild(strokePath);
document.body.appendChild(svg);

We create an SVG element that overlays the entire slide. It contains two paths:

  • fillPath: The solid fill that appears after drawing completes

  • strokePath: The animated stroke that draws on

The Draw-On Magic

The core animation technique uses SVG's stroke-dasharray and stroke-dashoffset properties. Here's the concept:

  1. Set stroke-dasharray to the path's total length

  2. Set stroke-dashoffset to the same length (hides the entire stroke)

  3. Animate stroke-dashoffset from full length to 0 (reveals the stroke progressively)

totalLength = strokePath.getTotalLength();

strokePath.setAttribute('stroke-dasharray', totalLength);
gsap.set(strokePath, { strokeDashoffset: totalLength }); // Fully hidden

// To reveal 50% of the stroke:
gsap.set(strokePath, { strokeDashoffset: totalLength * 0.5 });

Syncing with the Timeline

This is where the magic happens. We read Storyline's progress bar to determine the current playhead position:

function getProgressPercentage() {
  const computedWidth = window.getComputedStyle(progressFill).width;
  const parentWidth = window.getComputedStyle(progressFill.parentElement).width;
  
  if (computedWidth && parentWidth) {
    const widthPx = parseFloat(computedWidth);
    const parentPx = parseFloat(parentWidth);
    return (widthPx / parentPx) * 100;
  }
  return 0;
}

Then we use requestAnimationFrame to continuously sync our animation:

function sync() {
  updatePath();
  
  const progressPct = getProgressPercentage();
  const pct = progressPct / 100;
  const t = pct * SLIDE_LENGTH; // Current time in seconds
  
  // Calculate how far through the draw animation we should be
  const drawPct = (t - DRAW_START) / DRAW_DURATION;
  
  // Apply the appropriate stroke offset
  const clamped = Math.max(0, Math.min(1, drawPct));
  gsap.set(strokePath, {
    strokeDashoffset: totalLength * (1 - clamped)
  });
  
  requestAnimationFrame(sync);
}

This creates a scrub-friendly animation that stays perfectly in sync whether the user plays, pauses, or drags the timeline.

Step 4: The Complete Code

Here's the full script ready to copy and customize:

(function () {
  if (typeof gsap === 'undefined') {
    console.error('GSAP library required but not found.');
    return;
  }

  const OVAL_IDS = [
    // Replace with your data-model-ids
    '5w9p1oRm1rx', '6LmAsv0kF5T', '5ddRPB2TKrk', '5ZR8p16WR7N', '6qo1Hi8eitj',
    '65bxjWnzY0A', '6Sq05MbsCPK', '5rcTZR6tWHp', '6ZhjskvWz68', '6cBNoE7ywlC',
    '5vXsqk4CNrG', '5jXsazaVcmW', '62FQ7yZyEnl', '6eyUZ4RzoID', '5uMZGwt9ZCm',
    '6GWtAJwdOX7', '62bVWhUtFBF', '6OcZpytEsdw', '5v7Zn7lBo2x'
  ];
  const COLOR = '#C0504D';
  const STROKE_WIDTH = 4;
  const DRAW_START = 0.5;
  const DRAW_DURATION = 3;
  const POLL_MS = 50;
  const MAX_TRIES = 60;

  let animationFrameId = null;
  let svgElement = null;

  function dom(id) {
    const element = document.querySelector(`[data-model-id="${id}"]`);
    if (element) return element;
    if (typeof $ !== 'undefined' && $) {
      const jqElement = $(`[data-model-id="${id}"]`)[0];
      if (jqElement) return jqElement;
    }
    return null;
  }

  function waitForAll(ids, callback, tries = 0) {
    const elements = ids.map(dom);
    if (elements.every(Boolean)) return callback(elements);

    if (tries >= MAX_TRIES) {
      const missing = ids.filter((id, i) => !elements[i]);
      console.error('Ovals not found. Missing IDs:', missing);
      return;
    }

    setTimeout(() => waitForAll(ids, callback, tries + 1), POLL_MS);
  }

  function getSlideDurationInSeconds(callback) {
    const input = document.querySelector('input[type="range"][data-ref="progressBar"]');
    if (!input) return setTimeout(() => getSlideDurationInSeconds(callback), 50);
    const max = input.max || input.getAttribute('max');
    if (max && !isNaN(parseFloat(max))) return callback(parseFloat(max) / 1000);
    setTimeout(() => getSlideDurationInSeconds(callback), 50);
  }

  function cleanup() {
    if (animationFrameId !== null) {
      cancelAnimationFrame(animationFrameId);
      animationFrameId = null;
    }
    if (svgElement && svgElement.parentNode) {
      svgElement.parentNode.removeChild(svgElement);
      svgElement = null;
    }
  }

  window.addEventListener('beforeunload', cleanup);
  cleanup();

  waitForAll(OVAL_IDS, function (els) {
    getSlideDurationInSeconds(function (SLIDE_LENGTH) {
      const NS = 'http://www.w3.org/2000/svg';
      const svg = document.createElementNS(NS, 'svg');
      const fillPath = document.createElementNS(NS, 'path');
      const strokePath = document.createElementNS(NS, 'path');

      svg.appendChild(fillPath);
      svg.appendChild(strokePath);
      document.body.appendChild(svg);
      svgElement = svg;

      Object.assign(svg.style, {
        position: 'fixed',
        inset: 0,
        width: '100vw',
        height: '100vh',
        pointerEvents: 'none',
        zIndex: 9998
      });

      let totalLength = 0;
      let hasFadedInFill = false;

      gsap.set([strokePath, fillPath], { opacity: 0 });

      function updatePath() {
        const points = els.map(el => {
          const r = el.getBoundingClientRect();
          return [r.left + r.width / 2, r.top + r.height / 2];
        });
        const d = points.map(([x, y], i) => `${i ? 'L' : 'M'}${x},${y}`).join(' ') + ' Z';

        fillPath.setAttribute('d', d);
        strokePath.setAttribute('d', d);

        if (!totalLength) {
          totalLength = strokePath.getTotalLength();

          strokePath.setAttribute('fill', 'none');
          strokePath.setAttribute('stroke', COLOR);
          strokePath.setAttribute('stroke-width', STROKE_WIDTH);
          strokePath.setAttribute('stroke-linecap', 'round');
          gsap.set(strokePath, {
            strokeDasharray: totalLength,
            strokeDashoffset: totalLength
          });

          fillPath.setAttribute('fill', COLOR);
          fillPath.setAttribute('stroke', 'none');
          gsap.set(fillPath, { fillOpacity: 0 });
        }
      }

      const progressFill = document.querySelector('div[data-ref="progressBarFill"]');
      if (!progressFill) {
        console.warn('No progress bar found');
        cleanup();
        return;
      }

      function getProgressPercentage() {
        const computedWidth = window.getComputedStyle(progressFill).width;
        const parentWidth = window.getComputedStyle(progressFill.parentElement).width;

        if (computedWidth && parentWidth) {
          const widthPx = parseFloat(computedWidth);
          const parentPx = parseFloat(parentWidth);
          if (!isNaN(widthPx) && !isNaN(parentPx) && parentPx > 0) {
            return (widthPx / parentPx) * 100;
          }
        }
        return 0;
      }

      function sync() {
        updatePath();

        const progressPct = getProgressPercentage();
        if (!totalLength) {
          animationFrameId = requestAnimationFrame(sync);
          return;
        }

        const pct = progressPct / 100;
        const t = pct * SLIDE_LENGTH;

        let freeze = false;
        if (typeof GetPlayer === 'function') {
          try {
            const player = GetPlayer();
            if (player && typeof player.GetVar === 'function') {
              freeze = player.GetVar('AnimationFreeze') || false;
            }
          } catch (e) {}
        }

        const start = DRAW_START;
        const end = DRAW_START + DRAW_DURATION;
        const drawPct = (t - start) / DRAW_DURATION;

        if (!freeze) {
          if (t < start) {
            gsap.set([strokePath, fillPath], { opacity: 0, fillOpacity: 0 });
            gsap.set(strokePath, { strokeDashoffset: totalLength });
            hasFadedInFill = false;
          } else if (t >= end) {
            gsap.set(strokePath, { strokeDashoffset: 0, opacity: 1 });
            if (!hasFadedInFill) {
              hasFadedInFill = true;
              gsap.to(fillPath, {
                opacity: 1,
                fillOpacity: 1,
                duration: 1,
                ease: 'power1.out'
              });
            }
          } else {
            const clamped = Math.max(0, Math.min(1, drawPct));
            gsap.set(strokePath, {
              strokeDashoffset: totalLength * (1 - clamped),
              opacity: 1
            });
            gsap.set(fillPath, { opacity: 0, fillOpacity: 0 });
            hasFadedInFill = false;
          }
        }

        animationFrameId = requestAnimationFrame(sync);
      }

      sync();
    });
  });
})();

Step 5: Adding the Script to Storyline

  1. Open your Storyline project and navigate to the slide with your timeline

  2. Add a trigger: Execute JavaScript when the timeline starts

  3. Paste your script into the JavaScript editor and press ok.

Customization Options

Change the Timing

Adjust DRAW_START and DRAW_DURATION to control when and how fast the animation runs:

const DRAW_START = 1;      // Start at 1 second
const DRAW_DURATION = 5;   // Take 5 seconds to complete

Change the Appearance

Modify the color and stroke width:

const COLOR = '#3498db';    // A nice blue
const STROKE_WIDTH = 6;     // Thicker line

Add Animation Freeze Control

The script already checks for a Storyline variable called AnimationFreeze. Create this as a True/False variable in Storyline, then use triggers to pause the animation whenever you need.

Disable the Fill

If you only want the stroke effect without the fill, find this line and remove it or set opacity to 0:

gsap.to(fillPath, {
  opacity: 0,  // Change from 1 to 0
  // ...
});

Troubleshooting Common Issues

Animation doesn't appear:

  • Verify all data-model-ids are correct

  • Check the browser console for error messages

  • Ensure GSAP loaded before your script

Animation plays but isn't synced:

  • Make sure the progress bar element exists (div[data-ref="progressBarFill"])

  • Verify your slide has a timeline (not just "no timeline" mode)

Shape appears in wrong position:

  • The SVG uses viewport coordinates—if your course displays at different sizes, the positioning may shift

  • Consider using responsive design techniques or fixed player dimensions

Script runs multiple times:

  • The cleanup function handles this, but verify you're not duplicating the web object

Wrapping Up

You now have a powerful, timeline-synchronized draw-on animation for Articulate Storyline. This technique opens up countless possibilities: animated diagrams, progressive reveals, interactive infographics, and more.

The key concepts to remember:

  1. Use SVG's stroke-dashoffset for the draw effect

  2. Sync to Storyline's progress bar for timeline awareness

  3. Use requestAnimationFrame for smooth, efficient updates

  4. Always include cleanup functions for stability

Try experimenting with multiple shapes, different easing functions, or chained animations. Once you understand the foundation, the creative possibilities are endless.


Nathan Stoker

I build custom eLearning in Storyline, Rise and JavaScript, and I make the free tools and templates on this site. Need an interaction like this in your course? Let's talk.

Work with me · Browse templates

Related posts