Search code examples
htmlcsssvgsvg-animate

SVG straight line animation CSS


I am trying to achieve this (the picture below) in using SVG path for animation in a website. I saw this https://css-tricks.com/svg-line-animation-works/ and wanted to try it. But i am not sure how do i create the path out and the animation. Please do help me! Thanks

enter image description here


Solution

  • You can use svg code for animation. You can use CSS animation on svg paths.

    .st0{
    fill:none;
    stroke:#000000;
    stroke-miterlimit:10;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    -webkit-animation: draw1 4s linear forwards;
    animation: draw1 4s linear forwards;
    }
    .st1{
    fill:none;
    stroke:#000000;
    stroke-miterlimit:10;
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    -webkit-animation: draw2 3s linear 2s forwards;
    animation: draw2 3s linear 2s forwards;
    }
      
    @-webkit-keyframes draw1{
      to {stroke-dashoffset: 0;}
    }
    @keyframes draw1{
      to {stroke-dashoffset: 0;}
    }
    @-webkit-keyframes draw2{
      to {stroke-dashoffset: 0;}
    }
    @keyframes draw2{
      to {stroke-dashoffset: 0;}
    }
    <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
    	 viewBox="0 0 614 53" style="enable-background:new 0 0 614 53;" xml:space="preserve">
    <polyline class="st0" points="0.5,53 0.5,20.7 613.5,20.7 613.5,53 "/>
    <line class="st1" x1="307" y1="53" x2="307" y2="0"/>
    </svg>