Svg animation draw

Size
5,545 Kb
Views
6,072

How do I make an svg animation draw?

What is a svg animation draw? How do you make a svg animation draw? This script and codes were developed by Szymon Dziewoński on 23 December 2022, Friday.

Svg animation draw Previews

Svg animation draw - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Svg animation draw</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <li class="portfolioLogo"> <figure class="drawings mud"> <img class="illustration" src="http://szymondziewonski.com/pictures/work/mud/logo.png" alt="" /> <svg class="line-drawing" id="mud" width="180" height="180" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 180"> <g> <path fill="#ffffff" opacity="1.00" d=" M 36.10 46.28 C 46.57 35.60 60.92 28.74 75.86 27.57 C 92.90 25.90 110.46 31.64 123.34 42.91 C 134.75 52.65 142.05 66.60 144.70 81.28 C 148.28 83.60 151.85 85.98 154.82 89.09 C 153.87 98.30 150.64 109.49 141.16 113.20 C 138.81 118.56 133.67 121.96 128.06 123.11 C 129.38 120.72 130.38 118.19 131.21 115.60 C 129.43 115.64 127.55 116.05 125.87 115.30 C 122.22 113.56 121.49 108.64 117.95 106.91 C 114.41 107.07 113.81 111.56 113.79 114.33 C 113.29 114.59 112.80 114.85 112.31 115.12 C 112.75 121.07 113.73 127.22 117.73 131.95 C 115.82 132.61 113.88 133.14 111.95 133.75 C 114.34 133.83 116.63 133.13 118.58 131.75 C 113.55 127.72 116.62 120.52 113.19 115.66 C 113.88 115.34 114.58 115.02 115.28 114.71 C 119.69 119.08 116.46 125.89 120.02 130.63 C 123.05 128.92 124.85 125.88 126.68 123.05 C 127.99 124.70 128.07 126.85 128.44 128.84 C 129.54 127.22 130.64 125.59 131.83 124.03 C 132.27 132.01 125.72 137.53 119.99 141.92 C 99.67 157.87 69.36 159.00 47.64 145.13 C 48.55 138.93 54.14 135.07 59.37 132.56 C 68.84 128.26 79.77 126.61 89.96 129.07 C 91.93 133.27 91.61 138.26 89.00 142.11 C 91.38 142.82 93.76 143.53 96.16 144.18 C 95.50 145.22 94.85 146.26 94.20 147.30 C 101.91 147.88 111.37 147.07 116.26 140.24 C 113.36 140.67 109.83 141.83 107.33 139.64 C 104.69 136.79 104.44 132.36 101.34 129.85 C 97.17 126.16 93.19 120.89 93.83 115.03 C 96.00 110.08 102.57 111.09 106.52 108.50 C 110.88 105.54 116.29 102.86 121.66 104.42 C 125.50 105.88 124.48 112.07 128.94 112.57 C 134.94 111.49 140.62 108.94 145.89 105.92 C 146.10 103.97 146.58 102.03 146.44 100.07 C 143.78 97.52 140.67 95.50 137.73 93.30 C 139.55 91.83 141.95 91.46 144.10 90.68 C 146.08 91.44 148.10 92.58 150.29 91.97 C 147.25 84.93 139.36 81.85 133.05 78.34 C 129.01 79.88 124.94 81.39 120.88 82.88 C 123.60 80.48 126.59 78.40 129.46 76.19 C 127.77 71.42 125.73 66.79 123.80 62.12 C 114.27 57.69 104.72 53.27 95.35 48.52 C 92.57 46.33 91.38 42.68 88.81 40.28 C 81.06 37.66 72.96 36.31 64.96 34.67 C 66.00 38.41 67.38 42.06 68.50 45.78 C 69.87 46.73 71.26 47.64 72.65 48.56 C 72.25 49.25 71.44 50.63 71.04 51.32 C 60.42 45.68 47.88 43.79 36.10 46.28 M 96.24 117.13 C 96.46 123.04 102.02 126.38 105.49 130.44 C 107.31 132.26 107.10 135.34 109.19 136.92 C 110.69 137.79 112.46 138.07 114.11 138.55 C 113.43 136.53 110.72 138.01 109.50 136.44 C 108.14 134.54 108.20 131.95 106.86 130.00 C 104.26 126.15 99.83 123.57 98.31 118.99 C 97.86 117.71 97.57 115.64 99.23 115.11 C 102.17 113.95 105.23 113.02 107.90 111.26 C 104.12 113.33 97.44 111.86 96.24 117.13 Z" /> <path fill="#ffffff" opacity="1.00" d=" M 68.83 39.04 C 73.36 39.72 77.62 41.46 82.05 42.57 C 86.76 43.36 90.08 47.15 92.86 50.73 C 88.93 48.92 85.12 46.87 81.21 45.00 C 81.63 46.06 82.47 48.18 82.89 49.23 C 81.58 51.29 80.13 53.26 78.60 55.15 C 77.52 51.37 76.70 47.48 75.13 43.86 C 73.29 41.95 70.81 40.81 68.83 39.04 Z" /> <path fill="#ffffff" opacity="1.00" d=" M 98.16 63.32 C 100.59 63.15 102.74 64.34 104.88 65.29 C 104.46 66.51 103.68 66.62 102.55 65.63 C 101.05 64.93 99.55 64.21 98.16 63.32 Z" /> <path fill="#ffffff" opacity="1.00" d=" M 105.32 67.30 C 105.62 66.56 105.96 65.86 106.36 65.17 C 112.32 68.30 118.94 69.95 125.18 72.43 C 121.86 74.49 118.32 76.16 114.83 77.93 L 114.67 76.28 C 113.08 76.26 111.49 76.25 109.91 76.24 C 107.34 73.05 104.72 69.91 102.20 66.69 C 104.79 67.53 107.42 68.30 110.10 68.80 C 108.65 67.94 107.01 67.39 105.32 67.30 Z" /> <path fill="#ffffff" opacity="1.00" d=" M 29.00 75.57 C 50.53 70.34 74.22 71.29 94.16 81.60 C 99.22 84.43 104.45 87.30 108.47 91.55 C 107.65 91.85 106.02 92.45 105.20 92.75 C 83.24 76.64 54.49 71.33 27.91 76.30 C 28.18 76.12 28.73 75.75 29.00 75.57 Z" /> <path fill="#ffffff" opacity="1.00" d=" M 53.13 81.38 C 57.16 79.69 61.69 80.36 65.92 80.78 C 78.88 82.63 90.91 88.56 101.66 95.82 C 100.43 96.42 99.19 97.00 97.96 97.59 C 86.81 93.78 74.97 91.00 63.13 92.34 C 56.84 92.90 50.74 94.66 44.78 96.69 C 59.38 88.25 77.96 87.68 93.60 93.61 C 93.08 92.92 92.46 92.27 91.46 92.36 C 79.36 86.91 66.65 81.30 53.13 81.38 Z" /> </g> </svg> </figure> </li> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Svg animation draw - Script Codes CSS Codes

*{ margin: 0; padding: 0;
}
.portfolioLogo{ width: 180px; height: 180px; list-style-type: none;
}
svg { pointer-events: none;
}
.portfolioLogo{ line-height: none;
}
figure.drawings { margin: 0; padding: 0; position: relative; width: 180px; height: 180px;
}
.illustration { position: absolute; top: 0; left: 0; bottom: 0; right: 0; opacity: 0;
}
.show { opacity: 1;
}
.hide { opacity: 0;
}
.line-drawing,
.illustration { -webkit-transition: opacity 0.5s; transition: opacity 0.5s;
}
.line-drawing path { fill: none;
}
path.line-round { stroke-linecap: butt;
}
.drawings path{ stroke-width: 1;
}
figure.drawings.mud{ background-image: url("http://szymondziewonski.com/pictures/work/mud/logoBg.jpg");
}
figure.mud path{ stroke: #fff;
}

Svg animation draw - Script Codes JS Codes

/** * svganimations.js v1.0.0 * http://www.codrops.com * * the svg path animation is based on http://24ways.org/2013/animating-vectors-with-svg/ by Brian Suda (@briansuda) * * Licensed under the MIT license. * https://www.opensource.org/licenses/mit-license.php * * Copyright 2013, Codrops * http://www.codrops.com */
'use strict'; var docElem = window.document.documentElement; window.requestAnimFrame = function() { return ( window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(/* function */ callback) { window.setTimeout(callback, 1000 / 60); } ); }(); window.cancelAnimFrame = function() { return ( window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCancelAnimationFrame || function(id) { window.clearTimeout(id); } ); }(); function SVGEl(el) { this.el = el; this.image = this.el.previousElementSibling; this.current_frame = 0; this.total_frames = 120; this.path = new Array(); this.length = new Array(); this.handle = 0; this.init(); } SVGEl.prototype.init = function() { var self = this; [].slice.call(this.el.querySelectorAll('path')).forEach(function(path, i) { self.path[i] = path; var l = self.path[i].getTotalLength(); self.length[i] = l; self.path[i].style.strokeDasharray = l + ' ' + l; self.path[i].style.strokeDashoffset = l; }); }; SVGEl.prototype.render = function() { if (this.rendered) return; this.rendered = true; this.draw(); }; SVGEl.prototype.draw = function() { var self = this, progress = this.current_frame / this.total_frames; if (progress > 1) { window.cancelAnimFrame(this.handle); this.showImage(); } else { this.current_frame++; for (var j = 0, len = this.path.length; j < len; j++) { this.path[j].style.strokeDashoffset = Math.floor(this.length[j] * (1 - progress)); } this.handle = window.requestAnimFrame(function() { self.draw(); }); } }; SVGEl.prototype.showImage = function() { $(this.image).addClass('show'); $("svg").attr("class", "line-drawing hide"); }; function getViewportH() { var client = docElem['clientHeight'], inner = window['innerHeight']; if (client < inner) return inner; else return client; } function scrollY() { return window.pageYOffset || docElem.scrollTop; } // http://stackoverflow.com/a/5598797/989439 function getOffset(el) { var offsetTop = 0, offsetLeft = 0; do { if (!isNaN(el.offsetTop)) { offsetTop += el.offsetTop; } if (!isNaN(el.offsetLeft)) { offsetLeft += el.offsetLeft; } } while (el === el.offsetParent) return { top: offsetTop, left: offsetLeft }; } function inViewport(el, h) { var elH = el.offsetHeight, scrolled = scrollY(), viewed = scrolled + getViewportH(), elTop = getOffset(el).top, elBottom = elTop + elH, // if 0, the element is considered in the viewport as soon as it enters. // if 1, the element is considered in the viewport only when it's fully inside // value in percentage (1 >= h >= 0) h = h || 0; return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; } function init() { var svgs = Array.prototype.slice.call(document.querySelectorAll('.portfolioLogo svg')), svgArr = new Array(), didScroll = false, resizeTimeout; // the svgs already shown... svgs.forEach(function(el, i) { var svg = new SVGEl(el); svgArr[i] = svg; setTimeout(function(el) { return function() { if (inViewport(el.parentNode)) { svg.render(); } }; }(el), 250); }); var scrollHandler = function() { if (!didScroll) { didScroll = true; setTimeout(function() { scrollPage(); }, 60); } }, scrollPage = function() { svgs.forEach(function(el, i) { if (inViewport(el.parentNode, 0.5)) { svgArr[i].render(); } }); didScroll = false; }, resizeHandler = function() { function delayed() { scrollPage(); resizeTimeout = null; } if (resizeTimeout) { clearTimeout(resizeTimeout); } resizeTimeout = setTimeout(delayed, 200); }; window.addEventListener('scroll', scrollHandler, false); window.addEventListener('resize', resizeHandler, false); } init();
Svg animation draw - Script Codes
Svg animation draw - Script Codes
Home Page Home
Developer Szymon Dziewoński
Username SzymonDziewonski
Uploaded December 23, 2022
Rating 3
Size 5,545 Kb
Views 6,072
Do you need developer help for Svg animation draw?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Szymon Dziewoński (SzymonDziewonski) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!