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

              
                <body>
    <div id="ticker">Depth:<span>0</span></div>
    <div class="slide" id="v1"><span>Scroll-Controlled SVG Fill</span><br/><small>SVG paths of different lengths begin and end animating at the same scroll points</div>
  <!--SVG Test Data-->
  <div class="slide" id="v2">
   <svg version="1.1" id="avantrogue_svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="350.67px" height="234px" viewBox="0 0 350.67 234" style="enable-background:new 0 0 350.67 234;" xml:space="preserve">
<path style="fill:none;stroke:#F49020;stroke-miterlimit:10;" d="M19.48,193.99h3.97l15.11,35.54h-4.92l-3.61-8.74H12.25l-3.67,8.74
	H3.82L19.48,193.99z M21.39,199.42h-0.1l-7.38,17.47h14.51L21.39,199.42z"/>
<path style="fill:none;stroke:#F49020;stroke-miterlimit:10;" d="M36.1,193.99h4.77l10.95,29.22h0.1l11.3-29.22h4.47l-13.91,35.54
	h-4.07L36.1,193.99z"/>
<path style="fill:none;stroke:#F49020;stroke-miterlimit:10;" d="M80.93,193.99h3.97l15.11,35.54h-4.92l-3.61-8.74H73.7l-3.66,8.74
	h-4.77L80.93,193.99z M82.84,199.42h-0.1l-7.38,17.47h14.51L82.84,199.42z"/>
<path style="fill:none;stroke:#F49020;stroke-miterlimit:10;" d="M104.73,193.99h5.32l20.58,29.52h0.1v-29.52h4.22v35.54h-5.32
	l-20.59-29.52h-0.1v29.52h-4.22V193.99z"/>
<path style="fill:none;stroke:#F49020;stroke-miterlimit:10;" d="M167.64,197.91h-11.75v31.63h-4.22v-31.63h-11.75v-3.92h27.71
	V197.91z"/>
<path style="fill:none;stroke:#F49020;stroke-width:2;stroke-miterlimit:10;" d="M171.76,193.99h13.76c1.81,0,3.52,0.18,5.15,0.53
	c1.62,0.35,3.05,0.94,4.27,1.76c1.22,0.82,2.19,1.93,2.91,3.31c0.72,1.39,1.08,3.12,1.08,5.2c0,2.51-0.65,4.64-1.96,6.4
	c-1.3,1.76-3.21,2.87-5.72,3.34l9.04,15.01h-9.39l-7.43-14.21h-3.87v14.21h-7.83V193.99z M179.59,208.7h4.62
	c0.7,0,1.45-0.02,2.23-0.08c0.79-0.05,1.5-0.2,2.14-0.45c0.63-0.25,1.16-0.64,1.58-1.18c0.42-0.53,0.63-1.29,0.63-2.26
	c0-0.91-0.19-1.62-0.55-2.16c-0.37-0.53-0.84-0.95-1.41-1.23c-0.57-0.28-1.22-0.48-1.96-0.58c-0.74-0.1-1.45-0.15-2.16-0.15h-5.12
	V208.7z"/>
<path style="fill:none;stroke:#F49020;stroke-width:2;stroke-miterlimit:10;" d="M202.39,211.77c0-2.84,0.48-5.42,1.43-7.73
	c0.95-2.31,2.29-4.28,3.99-5.9c1.71-1.62,3.73-2.87,6.08-3.74c2.34-0.87,4.9-1.31,7.68-1.31c2.78,0,5.34,0.43,7.68,1.31
	c2.34,0.87,4.37,2.12,6.07,3.74c1.71,1.62,3.04,3.59,3.99,5.9c0.96,2.31,1.43,4.89,1.43,7.73c0,2.85-0.48,5.42-1.43,7.73
	c-0.95,2.31-2.28,4.27-3.99,5.9c-1.71,1.63-3.73,2.87-6.07,3.74c-2.34,0.87-4.9,1.3-7.68,1.3c-2.78,0-5.34-0.44-7.68-1.3
	c-2.35-0.87-4.37-2.12-6.08-3.74c-1.71-1.62-3.04-3.59-3.99-5.9C202.86,217.19,202.39,214.61,202.39,211.77z M210.52,211.77
	c0,1.67,0.26,3.21,0.78,4.6c0.52,1.39,1.26,2.59,2.24,3.61c0.97,1.02,2.13,1.81,3.49,2.38c1.35,0.57,2.87,0.86,4.54,0.86
	c1.67,0,3.19-0.29,4.54-0.86c1.35-0.57,2.52-1.36,3.49-2.38c0.97-1.02,1.71-2.23,2.23-3.61c0.52-1.39,0.78-2.92,0.78-4.6
	c0-1.64-0.26-3.16-0.78-4.57c-0.52-1.41-1.26-2.62-2.23-3.64c-0.97-1.02-2.13-1.81-3.49-2.38c-1.36-0.57-2.87-0.85-4.54-0.85
	c-1.67,0-3.19,0.28-4.54,0.85c-1.36,0.57-2.52,1.37-3.49,2.38c-0.97,1.02-1.72,2.24-2.24,3.64
	C210.78,208.6,210.52,210.13,210.52,211.77z"/>
<path style="fill:none;stroke:#F49020;stroke-width:2;stroke-miterlimit:10;" d="M278.24,227.03c-2.31,1.21-4.72,2.08-7.23,2.61
	c-2.51,0.54-5.07,0.8-7.68,0.8c-2.78,0-5.34-0.44-7.68-1.3c-2.35-0.87-4.37-2.12-6.08-3.74c-1.71-1.62-3.04-3.59-3.99-5.9
	c-0.95-2.31-1.43-4.89-1.43-7.73c0-2.84,0.48-5.42,1.43-7.73c0.95-2.31,2.29-4.28,3.99-5.9c1.71-1.62,3.73-2.87,6.08-3.74
	c2.34-0.87,4.9-1.31,7.68-1.31c2.84,0,5.46,0.34,7.86,1.03c2.39,0.69,4.5,1.87,6.3,3.54l-5.52,6.02c-1.07-1.11-2.28-1.94-3.62-2.51
	c-1.34-0.57-3.01-0.85-5.02-0.85c-1.67,0-3.19,0.28-4.54,0.85c-1.36,0.57-2.52,1.37-3.49,2.38c-0.97,1.02-1.72,2.24-2.24,3.64
	c-0.52,1.4-0.78,2.93-0.78,4.57c0,1.67,0.26,3.21,0.78,4.6c0.52,1.39,1.26,2.59,2.24,3.61c0.97,1.02,2.13,1.81,3.49,2.38
	c1.35,0.57,2.87,0.86,4.54,0.86c1.71,0,3.18-0.19,4.42-0.58c1.24-0.39,2.23-0.78,2.96-1.18v-5.77h-6.38v-7.23h13.91V227.03z"/>
<path style="fill:none;stroke:#F49020;stroke-width:2;stroke-miterlimit:10;" d="M315.09,215.83c0,2.11-0.32,4.05-0.95,5.82
	c-0.64,1.77-1.58,3.31-2.84,4.62c-1.25,1.31-2.82,2.33-4.69,3.06c-1.87,0.74-4.03,1.11-6.48,1.11c-2.48,0-4.65-0.37-6.53-1.11
	c-1.87-0.74-3.44-1.76-4.69-3.06c-1.26-1.3-2.2-2.84-2.84-4.62c-0.64-1.77-0.95-3.72-0.95-5.82v-21.84h7.83v21.54
	c0,1.11,0.18,2.13,0.53,3.06c0.35,0.94,0.84,1.75,1.48,2.44c0.63,0.69,1.4,1.22,2.28,1.61c0.89,0.38,1.85,0.58,2.89,0.58
	c1.04,0,1.99-0.19,2.86-0.58c0.87-0.39,1.62-0.92,2.26-1.61c0.64-0.69,1.13-1.5,1.48-2.44c0.35-0.94,0.53-1.96,0.53-3.06v-21.54
	h7.83V215.83z"/>
<path style="fill:none;stroke:#F49020;stroke-width:2;stroke-miterlimit:10;" d="M322.63,193.99h24.15v7.23h-16.31v6.63h15.41v7.23
	h-15.41v7.23h17.22v7.23h-25.05V193.99z"/>
<path d="M205.57,62.56 138.83,129.3 105.46,95.93 172.2,29.19 
	238.94,95.94 205.57,129.3 139.36,62.56 " style="fill:none;stroke:#F49020;stroke-width:2;stroke-dashoffset: 471.549072265625px; stroke-dasharray: 471.549072265625px;"></path>
<path d="M92.12,3.95 252.28,3.95 252.28,164.10999999999999 92.12,164.10999999999999 92.12,3.95" style="fill:none;stroke:#F49020;stroke-width:2;stroke-dashoffset: 640.6400146484375px; stroke-dasharray: 640.6400146484375px, 640.6400146484375px;"></path>
</svg>

  </div>
</body>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Oswald:300);
body{
    margin:0;
    width:100%;
    height:4000px;
    background-image: url(https://subtlepatterns.com/patterns/dark_wood.png);
    background-attachment: fixed;
}
#ticker{
position:fixed;
    top:15px;
    left:15px;
    color:#ffffff;
    font-size:14px;
    font-family: 'Oswald', sans-serif;
}
#v1{
    position:fixed;
    top:200px;
    font-size:36px;
    font-family: 'Oswald', sans-serif;
    font-weight:600;
    color:#ffffff;
    text-align:center;
    width:100%;
}
#v1 small{
  font-size:16px;
}
#v2{
  position:fixed;
  top:10px;
  font-size:36px;
    font-family: 'Oswald', sans-serif;
    font-weight:600;
    color:#ffffff;
    text-align:center;
    width:100%;
  opacity:1;
}
              
            
!

JS

              
                $(document).ready(function() {
    //cache window
    $window=$(window);
    replaceWithPaths($('svg'));
    var $tick=$("#ticker span"),
        $top= $(window).scrollTop(),
        $depth=$(document.body).offsetHeight;
    hideSVGPaths($('svg'));
    $(window).bind('scroll',function(e){
        $top= $(window).scrollTop();
        $tick.html($top);
    	
        
        if($top > 0 && $top <1000){  //SLIDE 1
                //grab existing element offset top value
                var $v1top=$('#v1').offset().top;
                
            $('#v1').css({
                "top": (200-(-$top*.1))+"px",
                "opacity":(1-($top*.001))
            })
        } 
      if($top <100000){ //SLIDE 2
          var $slide2=$top;
          $('#v2').css({
                "top": (($slide2*.01))+"px"
            })
          scrollSVGPaths($('svg'),$slide2);
          
          
        }
    });
    
});

//////////////////////////


jQuery.extend( jQuery.easing,
{
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
  }
});


//Adding SVG elements to DOM..
function SVG(tag) {
    return document.createElementNS('http://www.w3.org/2000/svg', tag);
}

//Reset if needed for manual animations..
function hideSVGPaths(parentElement) {

    var paths = $(parentElement).find('path');

    //for each PATH..
    $.each( paths, function() {

        //get the total length
        var totalLength = this.getTotalLength();

        //set PATHs to invisible
        $(this).css({
            'stroke-dashoffset': totalLength,
            'stroke-dasharray': totalLength + ' ' + totalLength
        });
    });
}

function scrollSVGPaths(_parentElement,scroll) {
    //capture PATH..
    var paths = $(_parentElement).find('path');

    //for each PATH..
    $.each( paths, function(i) {

        //get the total length
        var totalLength = this.getTotalLength();
        var appearDampener= .05;
        var singlePercent= (totalLength*0.01)*scroll;
        var singlePoint = Math.max(0, Math.min(singlePercent*appearDampener,totalLength));
      //Reset: set PATHs to invisible
        $(this).css({
            'stroke-dashoffset': totalLength-singlePoint,
            'stroke-dasharray': totalLength 
        });
      
    });
}


//Converts SVG elements to Paths if not done manually..

function replaceRectsWithPaths(parentElement) {


    var rects = $(parentElement).find('rect');

    $.each(rects, function() {

        var rectX = $(this).attr('x');
        var rectY = $(this).attr('y');

        var rectX2 = parseFloat(rectX) + parseFloat($(this).attr('width'));
        var rectY2 = parseFloat(rectY) + parseFloat($(this).attr('height'));

        var convertedPath = 'M' + rectX + ',' + rectY + ' ' + rectX2 + ',' + rectY + ' ' + rectX2 + ',' + rectY2 + ' ' + rectX + ',' + rectY2 + ' ' + rectX + ',' + rectY;


        $(SVG('path'))
        .attr('d', convertedPath)
        .attr('fill', $(this).attr('fill'))
        .attr('stroke', $(this).attr('stroke'))
        .attr('stroke-width', $(this).attr('stroke-width'))
        .insertAfter(this);

    });

    $(rects).remove();
}



function replaceLinesWithPaths(parentElement) {


    var lines = $(parentElement).find('line');

    $.each(lines, function() {

        var lineX1 = $(this).attr('x1');
        var lineY1 = $(this).attr('y1');

        var lineX2 = $(this).attr('x2');
        var lineY2 = $(this).attr('y2');

        var convertedPath = 'M' + lineX1 + ',' + lineY1 + ' ' + lineX2 + ',' + lineY2;


        $(SVG('path'))
        .attr('d', convertedPath)
        .attr('fill', $(this).attr('fill'))
        .attr('stroke', $(this).attr('stroke'))
        .attr('stroke-width', $(this).attr('stroke-width'))
        .insertAfter(this);

    });

    $(lines).remove();
}



function replaceCirclesWithPaths(parentElement) {

    var circles = $(parentElement).find('circle');

    $.each(circles, function() {

        var cX = $(this).attr('cx');
        var cY = $(this).attr('cy');
        var r = $(this).attr('r');
        var r2 = parseFloat(r * 2);

        var convertedPath = 'M' + cX + ', ' + cY + ' m' + (-r) + ', 0 ' + 'a ' + r + ', ' + r + ' 0 1,0 ' + r2 + ',0 ' + 'a ' + r + ', ' + r + ' 0 1,0 ' + (-r2) + ',0 ';

        $(SVG('path'))
        .attr('d', convertedPath)
        .attr('fill', $(this).attr('fill'))
        .attr('stroke', $(this).attr('stroke'))
        .attr('stroke-width', $(this).attr('stroke-width'))
        .insertAfter(this);

    });

    $(circles).remove();
}



function replaceEllipsesWithPaths(parentElement) {


    var ellipses = $(parentElement).find('ellipse');

    $.each(ellipses, function() {

        var cX = $(this).attr('cx');
        var cY = $(this).attr('cy');
        var rX = $(this).attr('rx');
        var rY = $(this).attr('ry');

        var convertedPath = 'M' + cX + ', ' + cY + ' m' + (-rX) + ', 0 ' + 'a ' + rX + ', ' + rY + ' 0 1,0 ' + rX*2 + ',0 ' + 'a ' + rX + ', ' + rY + ' 0 1,0 ' + (-rX*2) + ',0 ';

        $(SVG('path'))
        .attr('d', convertedPath)
        .attr('fill', $(this).attr('fill'))
        .attr('stroke', $(this).attr('stroke'))
        .attr('stroke-width', $(this).attr('stroke-width'))
        .insertAfter(this);

    });

    $(ellipses).remove();
}




function replacePolygonsWithPaths(parentElement) {


    var polygons = $(parentElement).find('polygon');

    $.each(polygons, function() {

        var points = $(this).attr('points');
        var polyPoints = points.split(/[ ,]+/);
        var endPoint = polyPoints[0] + ', ' + polyPoints[1];

        $(SVG('path'))
        .attr('d', 'M' + points + ' ' + endPoint)
        .attr('fill', $(this).attr('fill'))
        .attr('stroke', $(this).attr('stroke'))
        .attr('stroke-width', $(this).attr('stroke-width'))
        .insertAfter(this);

    });

    $(polygons).remove();
}




function replacePolylinesWithPaths(parentElement) {


    var polylines = $(parentElement).find('polyline');

    $.each(polylines, function() {

        var points = $(this).attr('points');

        $(SVG('path'))
        .attr('d', 'M' + points)
        .attr('fill', $(this).attr('fill'))
        .attr('stroke', $(this).attr('stroke'))
        .attr('stroke-width', $(this).attr('stroke-width'))
        .insertAfter(this);

    });

    $(polylines).remove();
}

function replaceWithPaths(parentElement) {

    replaceRectsWithPaths(parentElement);
    replaceLinesWithPaths(parentElement);
    replaceEllipsesWithPaths(parentElement);
    replaceCirclesWithPaths(parentElement);
    replacePolygonsWithPaths(parentElement);
    replacePolylinesWithPaths(parentElement);    
}
              
            
!
999px

Console