Unlocking the Art of SVG Animation: A Comprehensive Guide

Creating compelling SVG animations involves combining the vector power of Scalable Vector Graphics (SVG) with animation techniques like CSS, JavaScript, and SMIL. The process fundamentally revolves around manipulating the attributes of SVG elements over time to create the illusion of movement and transformation. This guide, informed by years of experience in web development and SVG artistry, will equip you with the knowledge and skills to craft stunning and performant SVG animations.

Understanding the Foundation: SVG Essentials

What is SVG and Why Use It for Animation?

SVG is an XML-based vector image format that allows for creating graphics that scale beautifully without loss of quality. Unlike raster images (like JPEGs or PNGs), SVGs are defined by mathematical equations, making them ideal for responsive design and animations that need to look sharp on all screen sizes. The key advantages of using SVG for animation include:

  • Scalability: No pixelation, regardless of the screen resolution.
  • Small File Size: Generally smaller than raster images, improving page load times.
  • Accessibility: SVGs are inherently accessible to screen readers.
  • Interactivity: SVGs can be easily manipulated with CSS, JavaScript, and SMIL.
  • Control: Precise control over individual elements and attributes.

Choosing the Right Animation Technique

Several methods exist for animating SVGs, each with its own strengths and weaknesses:

  • CSS Animations & Transitions: Ideal for simple animations and transitions, offering ease of use and good performance. Transitions smoothly change property values between two states, while animations define a sequence of keyframes.
  • JavaScript (and Libraries like GreenSock): Offers the most flexibility and control, allowing for complex animations, dynamic interactions, and real-time updates. Libraries like GreenSock Animation Platform (GSAP) simplify animation creation and provide advanced features.
  • SMIL (Synchronized Multimedia Integration Language): A declarative animation language specifically designed for XML-based formats. While powerful, SMIL is being deprecated in some browsers, making it less reliable for long-term projects.

Creating Your First SVG Animation with CSS

A Simple Example: Fading an SVG Element

Let’s start with a basic example using CSS transitions. We’ll fade an SVG circle in and out:


  



In this code:

  • We define an SVG circle with the ID “myCircle”.
  • We set the initial opacity to 1.
  • We use the transition property to smoothly change the opacity over 1 second with an ease-in-out timing function.
  • When the user hovers over the circle, the opacity changes to 0.2.

Utilizing Keyframes for More Complex Animations

For more complex animations, we can use CSS keyframes. Here’s an example that moves an SVG rectangle across the screen:


  



This example demonstrates:

  • Defining an animation named “moveRect” using the @keyframes rule.
  • Specifying the animation’s progress in percentages (0%, 50%, 100%).
  • Using the transform: translateX() function to move the rectangle horizontally.
  • Applying the animation to the rectangle using the animation property, setting the duration, timing function (linear), and iteration count (infinite).

Advanced SVG Animation with JavaScript and GSAP

Harnessing the Power of JavaScript

JavaScript provides unparalleled control over SVG animations. You can dynamically change SVG attributes based on user interactions, data updates, or other events. Here’s a basic example that changes the color of a circle when clicked:


  



This example showcases:

  • Accessing the SVG circle element using document.getElementById().
  • Adding an event listener for the “click” event.
  • Using setAttribute() to change the “fill” attribute of the circle.

Introduction to GreenSock Animation Platform (GSAP)

GSAP is a powerful JavaScript library specifically designed for creating high-performance animations. It simplifies complex animations and provides a robust API. Here’s how to use GSAP to animate the same circle we used earlier:

First, include GSAP in your HTML:


Then, write the JavaScript:


  



This code uses GSAP’s to() method to animate the circle:

  • duration: 2 sets the animation duration to 2 seconds.
  • x: 50 moves the circle 50 pixels along the x-axis.
  • rotation: 360 rotates the circle 360 degrees.
  • repeat: -1 makes the animation loop infinitely.
  • yoyo: true makes the animation reverse direction on each repeat.

Best Practices for SVG Animation

Optimizing Performance

  • Simplify your SVG: Reduce the number of paths and elements to improve rendering speed.
  • Use CSS transforms: Transforms are generally more performant than directly manipulating attributes like x and y.
  • Hardware Acceleration: Ensure your animations are hardware-accelerated by using properties like transform and opacity.
  • Throttle event handlers: If your animations are triggered by events, use throttling or debouncing to prevent excessive updates.
  • Consider using GSAP: GSAP is optimized for performance and offers features like easing functions that can enhance the visual appeal of your animations.

Accessibility Considerations

  • Provide alternative text: Use the </code> and <code><desc></code> elements within your SVG to provide descriptions for screen readers.</li> <li><strong>Ensure keyboard navigation:</strong> If your animations are interactive, ensure that they can be controlled using the keyboard.</li> <li><strong>Avoid flashing animations:</strong> Rapidly flashing animations can trigger seizures in people with photosensitive epilepsy.</li> <li><strong>Use ARIA attributes:</strong> ARIA attributes can provide additional information to screen readers, improving the accessibility of your animations.</li> </ul> <h2><span class="ez-toc-section" id="Frequently_Asked_Questions_FAQs"></span>Frequently Asked Questions (FAQs)<span class="ez-toc-section-end"></span></h2> <h3><span class="ez-toc-section" id="1_How_do_I_animate_the_stroke_of_an_SVG_path"></span>1. How do I animate the stroke of an SVG path?<span class="ez-toc-section-end"></span></h3> <p>Use the <code>stroke-dasharray</code> and <code>stroke-dashoffset</code> properties in CSS or JavaScript. <code>stroke-dasharray</code> defines the pattern of dashes and gaps, and <code>stroke-dashoffset</code> controls the starting point of the pattern, effectively animating the stroke appearance.</p> <h3><span class="ez-toc-section" id="2_Can_I_animate_SVG_filters"></span>2. Can I animate SVG filters?<span class="ez-toc-section-end"></span></h3> <p>Yes, you can animate SVG filters using CSS or JavaScript. However, filter animations can be performance-intensive, so optimize your filter effects and use them sparingly.</p> <h3><span class="ez-toc-section" id="3_How_do_I_trigger_an_SVG_animation_on_scroll"></span>3. How do I trigger an SVG animation on scroll?<span class="ez-toc-section-end"></span></h3> <p>Use JavaScript to detect when the SVG element is in the viewport and then start the animation. Libraries like Intersection Observer API can help simplify this process.</p> <h3><span class="ez-toc-section" id="4_Whats_the_difference_between_CSS_transitions_and_CSS_animations"></span>4. What’s the difference between CSS transitions and CSS animations?<span class="ez-toc-section-end"></span></h3> <p>Transitions smoothly change property values between two states (e.g., on hover), while animations define a sequence of keyframes that represent different points in the animation timeline.</p> <h3><span class="ez-toc-section" id="5_Is_SMIL_still_a_viable_option_for_SVG_animation"></span>5. Is SMIL still a viable option for SVG animation?<span class="ez-toc-section-end"></span></h3> <p>SMIL is being deprecated in some browsers, making it less reliable for long-term projects. CSS and JavaScript are generally preferred.</p> <h3><span class="ez-toc-section" id="6_How_do_I_debug_SVG_animations"></span>6. How do I debug SVG animations?<span class="ez-toc-section-end"></span></h3> <p>Use your browser’s developer tools to inspect the SVG element and its attributes during the animation. Check for errors in your CSS or JavaScript code. The “Animations” tab in Chrome DevTools is especially helpful.</p> <h3><span class="ez-toc-section" id="7_How_can_I_create_a_looping_SVG_animation"></span>7. How can I create a looping SVG animation?<span class="ez-toc-section-end"></span></h3> <p>In CSS, set the <code>animation-iteration-count</code> property to <code>infinite</code>. In JavaScript (with GSAP), use the <code>repeat: -1</code> option.</p> <h3><span class="ez-toc-section" id="8_How_do_I_pause_or_stop_an_SVG_animation_with_JavaScript"></span>8. How do I pause or stop an SVG animation with JavaScript?<span class="ez-toc-section-end"></span></h3> <p>You can pause CSS animations by setting the <code>animation-play-state</code> property to <code>paused</code>. With GSAP, use the <code>pause()</code> or <code>kill()</code> methods on the timeline.</p> <h3><span class="ez-toc-section" id="9_How_do_I_handle_SVG_animation_performance_issues_on_mobile_devices"></span>9. How do I handle SVG animation performance issues on mobile devices?<span class="ez-toc-section-end"></span></h3> <p>Simplify your SVG, use hardware acceleration, and optimize your animation code. Test your animations on a variety of mobile devices to identify performance bottlenecks.</p> <h3><span class="ez-toc-section" id="10_Can_I_use_SVG_animations_in_email"></span>10. Can I use SVG animations in email?<span class="ez-toc-section-end"></span></h3> <p>Support for SVG animations in email clients is limited. CSS animations are generally more reliable than JavaScript or SMIL in email.</p> <h3><span class="ez-toc-section" id="11_How_do_I_animate_multiple_SVG_elements_simultaneously"></span>11. How do I animate multiple SVG elements simultaneously?<span class="ez-toc-section-end"></span></h3> <p>Use CSS selectors or JavaScript to target multiple elements and apply the same animation. With GSAP, you can create a timeline and add animations for multiple elements to it.</p> <h3><span class="ez-toc-section" id="12_What_are_the_best_resources_for_learning_more_about_SVG_animation"></span>12. What are the best resources for learning more about SVG animation?<span class="ez-toc-section-end"></span></h3> <ul> <li><strong>MDN Web Docs:</strong> Comprehensive documentation on SVG and animation techniques.</li> <li><strong>GSAP Documentation:</strong> Detailed information on the GreenSock Animation Platform.</li> <li><strong>Codepen:</strong> A platform for sharing and experimenting with web code, including SVG animations.</li> <li><strong>Online Courses:</strong> Platforms like Udemy and Coursera offer courses on SVG animation.</li> </ul> <p>By mastering these techniques and adhering to best practices, you can unlock the full potential of SVG animation and create engaging and visually stunning experiences for your users. Remember to prioritize performance, accessibility, and user experience to ensure your animations are both beautiful and functional.</p> </div><!-- .entry-content .clear --> </div> </article><!-- #post-## --> <nav class="navigation post-navigation" aria-label="Posts"> <div class="nav-links"><div class="nav-previous"><a title="How to Download a Rented Movie from Google Play: A Comprehensive Guide" href="https://darkskiesfilm.com/how-to-download-a-rented-movie-from-google-play/" rel="prev"><span class="ast-post-nav" aria-hidden="true"><span aria-hidden="true" class="ahfb-svg-iconset ast-inline-flex svg-baseline"><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'><path d='M134.059 296H436c6.627 0 12-5.373 12-12v-56c0-6.627-5.373-12-12-12H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 239.029c-9.373 9.373-9.373 24.569 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296z'></path></svg></span> Previous</span> <p> How to Download a Rented Movie from Google Play: A Comprehensive Guide </p></a></div><div class="nav-next"><a title="Downloading Nigerian Movies: A Comprehensive Guide" href="https://darkskiesfilm.com/how-can-i-download-nigerian-movies/" rel="next"><span class="ast-post-nav" aria-hidden="true">Next <span aria-hidden="true" class="ahfb-svg-iconset ast-inline-flex svg-baseline"><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'><path d='M313.941 216H12c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12h301.941v46.059c0 21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.569 0-33.941l-86.059-86.059c-15.119-15.119-40.971-4.411-40.971 16.971V216z'></path></svg></span></span> <p> Downloading Nigerian Movies: A Comprehensive Guide </p></a></div></div> </nav> <div id="comments" class="comments-area comment-form-position-below "> <div id="respond" class="comment-respond"> <h3 id="reply-title" class="comment-reply-title">Leave a Comment <small><a rel="nofollow" id="cancel-comment-reply-link" href="/how-to-make-an-svg-animation/#respond" style="display:none;">Cancel Reply</a></small></h3><form action="https://darkskiesfilm.com/wp-comments-post.php" method="post" id="ast-commentform" class="comment-form"><p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> <span class="required-field-message">Required fields are marked <span class="required">*</span></span></p><div class="ast-row comment-textarea"><fieldset class="comment-form-comment"><legend class ="comment-form-legend"></legend><div class="comment-form-textarea ast-grid-common-col"><label for="comment" class="screen-reader-text">Type here..</label><textarea id="comment" name="comment" placeholder="Type here.." cols="45" rows="8" aria-required="true"></textarea></div></fieldset></div><div class="ast-comment-formwrap ast-row"> <p class="comment-form-author ast-grid-common-col ast-width-lg-33 ast-width-md-4 ast-float"> <label for="author" class="screen-reader-text">Name*</label> <input id="author" name="author" type="text" value="" placeholder="Name*" size="30" aria-required='true' autocomplete="name" /> </p> <p class="comment-form-email ast-grid-common-col ast-width-lg-33 ast-width-md-4 ast-float"> <label for="email" class="screen-reader-text">Email*</label> <input id="email" name="email" type="text" value="" placeholder="Email*" size="30" aria-required='true' autocomplete="email" /> </p> <p class="comment-form-url ast-grid-common-col ast-width-lg-33 ast-width-md-4 ast-float"> <label for="url" class="screen-reader-text">Website</label> <input id="url" name="url" type="text" value="" placeholder="Website" size="30" autocomplete="url" /> </p> </div> <p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" /> <label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time I comment.</label></p> <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment" /> <input type='hidden' name='comment_post_ID' value='180741' id='comment_post_ID' /> <input type='hidden' name='comment_parent' id='comment_parent' value='0' /> </p></form> </div><!-- #respond --> </div><!-- #comments --> </main><!-- #main --> </div><!-- #primary --> </div> <!-- ast-container --> </div><!-- #content --> <footer class="site-footer" id="colophon" itemtype="https://schema.org/WPFooter" itemscope="itemscope" itemid="#colophon"> <div class="site-below-footer-wrap ast-builder-grid-row-container site-footer-focus-item ast-builder-grid-row-full ast-builder-grid-row-tablet-full ast-builder-grid-row-mobile-full ast-footer-row-stack ast-footer-row-tablet-stack ast-footer-row-mobile-stack" data-section="section-below-footer-builder"> <div class="ast-builder-grid-row-container-inner"> <div class="ast-builder-footer-grid-columns site-below-footer-inner-wrap ast-builder-grid-row"> <div class="site-footer-below-section-1 site-footer-section site-footer-section-1"> <div class="ast-builder-layout-element ast-flex site-footer-focus-item ast-footer-copyright" data-section="section-footer-builder"> <div class="ast-footer-copyright"><p>Copyright © 2026 Dark Skies | Powered by <a href="https://wpastra.com" rel="nofollow noopener" target="_blank">Astra WordPress Theme</a></p> </div> </div> </div> </div> </div> </div> </footer><!-- #colophon --> </div><!-- #page --> <script type="speculationrules"> {"prefetch":[{"source":"document","where":{"and":[{"href_matches":"/*"},{"not":{"href_matches":["/wp-*.php","/wp-admin/*","/wp-content/uploads/*","/wp-content/*","/wp-content/plugins/*","/wp-content/themes/astra/*","/*\\?(.+)"]}},{"not":{"selector_matches":"a[rel~=\"nofollow\"]"}},{"not":{"selector_matches":".no-prefetch, .no-prefetch a"}}]},"eagerness":"conservative"}]} </script> <div data-rocket-location-hash="4e1ca7e08687b5a5aeeb03567a38aa28" id="ast-scroll-top" tabindex="0" class="ast-scroll-top-icon ast-scroll-to-top-right" data-on-devices="both"> <span class="ast-icon icon-arrow"><svg class="ast-arrow-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="26px" height="16.043px" viewbox="57 35.171 26 16.043" enable-background="new 57 35.171 26 16.043" xml:space="preserve"> <path d="M57.5,38.193l12.5,12.5l12.5-12.5l-2.5-2.5l-10,10l-10-10L57.5,38.193z" /> </svg></span> <span class="screen-reader-text">Scroll to Top</span> </div> <script> /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1); </script> <script async data-wp-strategy="async" fetchpriority="low" id="comment-reply-js" src="https://darkskiesfilm.com/wp-includes/js/comment-reply.min.js?ver=7.0.2"></script> <script id="astra-theme-js-js-extra"> var astra = {"break_point":"921","isRtl":"","is_scroll_to_id":"1","is_scroll_to_top":"1","is_header_footer_builder_active":"1","responsive_cart_click":"flyout","is_dark_palette":""}; //# sourceURL=astra-theme-js-js-extra </script> <script id="astra-theme-js-js" src="https://darkskiesfilm.com/wp-content/themes/astra/assets/js/minified/frontend.min.js?ver=4.13.6"></script> <script id="eztoc-scroll-scriptjs-js-extra"> var eztoc_smooth_local = {"scroll_offset":"30","add_request_uri":"","add_self_reference_link":""}; //# sourceURL=eztoc-scroll-scriptjs-js-extra </script> <script id="eztoc-scroll-scriptjs-js" src="https://darkskiesfilm.com/wp-content/plugins/easy-table-of-contents/assets/js/smooth_scroll.min.js?ver=2.0.85"></script> <script id="eztoc-js-cookie-js" src="https://darkskiesfilm.com/wp-content/plugins/easy-table-of-contents/vendor/js-cookie/js.cookie.min.js?ver=2.2.1"></script> <script id="eztoc-jquery-sticky-kit-js" src="https://darkskiesfilm.com/wp-content/plugins/easy-table-of-contents/vendor/sticky-kit/jquery.sticky-kit.min.js?ver=1.9.2"></script> <script id="eztoc-js-js-extra"> var ezTOC = {"smooth_scroll":"1","visibility_hide_by_default":"","scroll_offset":"30","fallbackIcon":"\u003Cspan class=\"\"\u003E\u003Cspan class=\"eztoc-hide\" style=\"display:none;\"\u003EToggle\u003C/span\u003E\u003Cspan class=\"ez-toc-icon-toggle-span\"\u003E\u003Csvg style=\"fill: #999;color:#999\" xmlns=\"http://www.w3.org/2000/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"\u003E\u003Cpath d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"\u003E\u003C/path\u003E\u003C/svg\u003E\u003Csvg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http://www.w3.org/2000/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"\u003E\u003Cpath d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"/\u003E\u003C/svg\u003E\u003C/span\u003E\u003C/span\u003E","chamomile_theme_is_on":""}; //# sourceURL=eztoc-js-js-extra </script> <script id="eztoc-js-js" src="https://darkskiesfilm.com/wp-content/plugins/easy-table-of-contents/assets/js/front.min.js?ver=2.0.85-1781093492"></script> <script id="rocket-browser-checker-js-after"> "use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}var RocketBrowserCompatibilityChecker=function(){function RocketBrowserCompatibilityChecker(options){_classCallCheck(this,RocketBrowserCompatibilityChecker),this.passiveSupported=!1,this._checkPassiveOption(this),this.options=!!this.passiveSupported&&options}return _createClass(RocketBrowserCompatibilityChecker,[{key:"_checkPassiveOption",value:function(self){try{var options={get passive(){return!(self.passiveSupported=!0)}};window.addEventListener("test",null,options),window.removeEventListener("test",null,options)}catch(err){self.passiveSupported=!1}}},{key:"initRequestIdleCallback",value:function(){!1 in window&&(window.requestIdleCallback=function(cb){var start=Date.now();return setTimeout(function(){cb({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-start))}})},1)}),!1 in window&&(window.cancelIdleCallback=function(id){return clearTimeout(id)})}},{key:"isDataSaverModeOn",value:function(){return"connection"in navigator&&!0===navigator.connection.saveData}},{key:"supportsLinkPrefetch",value:function(){var elem=document.createElement("link");return elem.relList&&elem.relList.supports&&elem.relList.supports("prefetch")&&window.IntersectionObserver&&"isIntersecting"in IntersectionObserverEntry.prototype}},{key:"isSlowConnection",value:function(){return"connection"in navigator&&"effectiveType"in navigator.connection&&("2g"===navigator.connection.effectiveType||"slow-2g"===navigator.connection.effectiveType)}}]),RocketBrowserCompatibilityChecker}(); //# sourceURL=rocket-browser-checker-js-after </script> <script id="rocket-preload-links-js-extra"> var RocketPreloadLinksConfig = {"excludeUris":"/(?:.+/)?feed(?:/(?:.+/?)?)?$|/(?:.+/)?embed/|/(index.php/)?(.*)wp-json(/.*|$)|/refer/|/go/|/recommend/|/recommends/","usesTrailingSlash":"1","imageExt":"jpg|jpeg|gif|png|tiff|bmp|webp|avif|pdf|doc|docx|xls|xlsx|php","fileExt":"jpg|jpeg|gif|png|tiff|bmp|webp|avif|pdf|doc|docx|xls|xlsx|php|html|htm","siteUrl":"https://darkskiesfilm.com","onHoverDelay":"100","rateThrottle":"3"}; //# sourceURL=rocket-preload-links-js-extra </script> <script id="rocket-preload-links-js-after"> (function() { "use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}();function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=function(){function n(e,t){i(this,n),this.browser=e,this.config=t,this.options=this.browser.options,this.prefetched=new Set,this.eventTime=null,this.threshold=1111,this.numOnHover=0}return e(n,[{key:"init",value:function(){!this.browser.supportsLinkPrefetch()||this.browser.isDataSaverModeOn()||this.browser.isSlowConnection()||(this.regex={excludeUris:RegExp(this.config.excludeUris,"i"),images:RegExp(".("+this.config.imageExt+")$","i"),fileExt:RegExp(".("+this.config.fileExt+")$","i")},this._initListeners(this))}},{key:"_initListeners",value:function(e){-1<this.config.onHoverDelay&&document.addEventListener("mouseover",e.listener.bind(e),e.listenerOptions),document.addEventListener("mousedown",e.listener.bind(e),e.listenerOptions),document.addEventListener("touchstart",e.listener.bind(e),e.listenerOptions)}},{key:"listener",value:function(e){var t=e.target.closest("a"),n=this._prepareUrl(t);if(null!==n)switch(e.type){case"mousedown":case"touchstart":this._addPrefetchLink(n);break;case"mouseover":this._earlyPrefetch(t,n,"mouseout")}}},{key:"_earlyPrefetch",value:function(t,e,n){var i=this,r=setTimeout(function(){if(r=null,0===i.numOnHover)setTimeout(function(){return i.numOnHover=0},1e3);else if(i.numOnHover>i.config.rateThrottle)return;i.numOnHover++,i._addPrefetchLink(e)},this.config.onHoverDelay);t.addEventListener(n,function e(){t.removeEventListener(n,e,{passive:!0}),null!==r&&(clearTimeout(r),r=null)},{passive:!0})}},{key:"_addPrefetchLink",value:function(i){return this.prefetched.add(i.href),new Promise(function(e,t){var n=document.createElement("link");n.rel="prefetch",n.href=i.href,n.onload=e,n.onerror=t,document.head.appendChild(n)}).catch(function(){})}},{key:"_prepareUrl",value:function(e){if(null===e||"object"!==(void 0===e?"undefined":r(e))||!1 in e||-1===["http:","https:"].indexOf(e.protocol))return null;var t=e.href.substring(0,this.config.siteUrl.length),n=this._getPathname(e.href,t),i={original:e.href,protocol:e.protocol,origin:t,pathname:n,href:t+n};return this._isLinkOk(i)?i:null}},{key:"_getPathname",value:function(e,t){var n=t?e.substring(this.config.siteUrl.length):e;return n.startsWith("/")||(n="/"+n),this._shouldAddTrailingSlash(n)?n+"/":n}},{key:"_shouldAddTrailingSlash",value:function(e){return this.config.usesTrailingSlash&&!e.endsWith("/")&&!this.regex.fileExt.test(e)}},{key:"_isLinkOk",value:function(e){return null!==e&&"object"===(void 0===e?"undefined":r(e))&&(!this.prefetched.has(e.href)&&e.origin===this.config.siteUrl&&-1===e.href.indexOf("?")&&-1===e.href.indexOf("#")&&!this.regex.excludeUris.test(e.href)&&!this.regex.images.test(e.href))}}],[{key:"run",value:function(){"undefined"!=typeof RocketPreloadLinksConfig&&new n(new RocketBrowserCompatibilityChecker({capture:!0,passive:!0}),RocketPreloadLinksConfig).init()}}]),n}();t.run(); }()); //# sourceURL=rocket-preload-links-js-after </script> <script id="astra-addon-js-js-extra"> var astraAddon = {"sticky_active":"","svgIconClose":"\u003Cspan class=\"ast-icon icon-close\"\u003E\u003Csvg viewbox=\"0 0 512 512\" aria-hidden=\"true\" role=\"img\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"18px\" height=\"18px\"\u003E\n \u003Cpath d=\"M71.029 71.029c9.373-9.372 24.569-9.372 33.942 0L256 222.059l151.029-151.03c9.373-9.372 24.569-9.372 33.942 0 9.372 9.373 9.372 24.569 0 33.942L289.941 256l151.03 151.029c9.372 9.373 9.372 24.569 0 33.942-9.373 9.372-24.569 9.372-33.942 0L256 289.941l-151.029 151.03c-9.373 9.372-24.569 9.372-33.942 0-9.372-9.373-9.372-24.569 0-33.942L222.059 256 71.029 104.971c-9.372-9.373-9.372-24.569 0-33.942z\" /\u003E\n \u003C/svg\u003E\u003C/span\u003E","hf_account_show_menu_on":"hover","hf_account_action_type":"link","is_header_builder_active":"1"}; //# sourceURL=astra-addon-js-js-extra </script> <script data-minify="1" id="astra-addon-js-js" src="https://darkskiesfilm.com/wp-content/cache/min/1/wp-content/uploads/astra-addon/astra-addon-68149701416825-17187812.js?ver=1782126540"></script> <script>window.lazyLoadOptions=[{elements_selector:"img[data-lazy-src],.rocket-lazyload,iframe[data-lazy-src]",data_src:"lazy-src",data_srcset:"lazy-srcset",data_sizes:"lazy-sizes",class_loading:"lazyloading",class_loaded:"lazyloaded",threshold:300,callback_loaded:function(element){if(element.tagName==="IFRAME"&&element.dataset.rocketLazyload=="fitvidscompatible"){if(element.classList.contains("lazyloaded")){if(typeof window.jQuery!="undefined"){if(jQuery.fn.fitVids){jQuery(element).parent().fitVids()}}}}}},{elements_selector:".rocket-lazyload",data_src:"lazy-src",data_srcset:"lazy-srcset",data_sizes:"lazy-sizes",class_loading:"lazyloading",class_loaded:"lazyloaded",threshold:300,}];window.addEventListener('LazyLoad::Initialized',function(e){var lazyLoadInstance=e.detail.instance;if(window.MutationObserver){var observer=new MutationObserver(function(mutations){var image_count=0;var iframe_count=0;var rocketlazy_count=0;mutations.forEach(function(mutation){for(var i=0;i<mutation.addedNodes.length;i++){if(typeof mutation.addedNodes[i].getElementsByTagName!=='function'){continue} if(typeof mutation.addedNodes[i].getElementsByClassName!=='function'){continue} images=mutation.addedNodes[i].getElementsByTagName('img');is_image=mutation.addedNodes[i].tagName=="IMG";iframes=mutation.addedNodes[i].getElementsByTagName('iframe');is_iframe=mutation.addedNodes[i].tagName=="IFRAME";rocket_lazy=mutation.addedNodes[i].getElementsByClassName('rocket-lazyload');image_count+=images.length;iframe_count+=iframes.length;rocketlazy_count+=rocket_lazy.length;if(is_image){image_count+=1} if(is_iframe){iframe_count+=1}}});if(image_count>0||iframe_count>0||rocketlazy_count>0){lazyLoadInstance.update()}});var b=document.getElementsByTagName("body")[0];var config={childList:!0,subtree:!0};observer.observe(b,config)}},!1)</script><script data-no-minify="1" async src="https://darkskiesfilm.com/wp-content/plugins/wp-rocket/assets/js/lazyload/17.8.3/lazyload.min.js"></script> <script>var rocket_beacon_data = {"ajax_url":"https:\/\/darkskiesfilm.com\/wp-admin\/admin-ajax.php","nonce":"8cf51357b8","url":"https:\/\/darkskiesfilm.com\/how-to-make-an-svg-animation","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":null,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"preload_fonts_exclusions":["api.fontshare.com","cdn.fontshare.com"],"processed_extensions":["woff2","woff","ttf"],"external_font_exclusions":[],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":["static.cloudflareinsights.com","rel=\"profile\"","rel=\"preconnect\"","rel=\"dns-prefetch\"","rel=\"icon\""]}</script><script data-name="wpr-wpr-beacon" src='https://darkskiesfilm.com/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body> </html> <!-- This website is like a Rocket, isn't it? Performance optimized by WP Rocket. Learn more: https://wp-rocket.me -->