{
    "componentChunkName": "component---src-components-blog-post-jsx",
    "path": "/blog/getting-started-with-svg-animation/",
    "result": {"data":{"site":{"siteMetadata":{"author":"Monica Powell","siteUrl":"https://www.aboutmonica.com"}},"mdx":{"id":"ad4098eb-d160-5de9-b5ac-d1cce349adfa","timeToRead":3,"body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Getting Started with SVG Animation\",\n  \"date\": \"2021-04-13T02:48:42.474Z\",\n  \"template\": \"post\",\n  \"draft\": true,\n  \"slug\": \"getting-started-with-svg-animation\",\n  \"tags\": [\"CSS\", \"SVG\", \"Animation\", \"Design\"],\n  \"category\": [\"tutorial\"],\n  \"description\": \"This is an article about the basics of SVG animation.\"\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar TableOfContents = makeShortcode(\"TableOfContents\");\nvar CodePen = makeShortcode(\"CodePen\");\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"I attended Cassie Evan's \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://www.cassie.codes/speaking/getting-started-with-svg-animation/\"\n  }, \"SVG masterclass on getting started with SVG animation\"), \" in February and have been enjoying creating and animating more SVGs in recent weeks. \"), mdx(TableOfContents, {\n    headings: props.tableOfContents,\n    mdxType: \"TableOfContents\"\n  }), mdx(\"h2\", {\n    \"id\": \"reading-and-writing-svgs\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#reading-and-writing-svgs\",\n    \"aria-label\": \"reading and writing svgs permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Reading and Writing SVGs\"), mdx(\"p\", null, \"You may be wondering what exactly are SVGs. \", mdx(\"del\", {\n    parentName: \"p\"\n  }, \"SVG's are magic!\"), \" The Scalable Vector Graphics (SVG) format is a human-readable image format. You can create and edit SVGs by writing XML or by editing the file in design software like Adobe Illustrator. SVG images are vector files that are mathematically calculated which means that even if you zoom into an SVG on a website or enlargen it for a billboard it will be just as sharp. In contrast, to vector files, pixel based images (generally photographs) will become blurry at different resolutions.\"), mdx(\"p\", null, \"One of the cool things about SVGs is that once you understand how to read an SVG file you can change the colors (known as fill or stroke) programmatically.\"), mdx(\"svg\", {\n    xmlns: \"http://www.w3.org/2000/svg\",\n    viewBox: \"0 0 1728 500\"\n  }, mdx(\"rect\", {\n    x: \"153.55\",\n    y: \"200\",\n    width: \"300\",\n    height: \"300\",\n    fill: \"#ff499e\"\n  }), mdx(\"rect\", {\n    x: \"519.55\",\n    y: \"200\",\n    width: \"300\",\n    height: \"300\",\n    fill: \"#99267e\"\n  }), mdx(\"rect\", {\n    x: \"883.41\",\n    y: \"200\",\n    width: \"300\",\n    height: \"300\",\n    fill: \"#9c5ea8\"\n  }), mdx(\"rect\", {\n    x: \"1263.41\",\n    y: \"200\",\n    width: \"300\",\n    height: \"300\",\n    fill: \"#798fd4\"\n  })), mdx(\"p\", null, mdx(\"em\", {\n    parentName: \"p\"\n  }, \"four squares generated by SVG's XML Markup\")), mdx(\"p\", null, \"The code block below this paragraph represents the four SVG squares above. Each of the squares is a \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"rect\"), \" with a different \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"fill\"), \" color. Since the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"width\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"height\"), \" is the same value of \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"300\"), \" these \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"rect\"), \"s appear as squares and all of the squares have the same \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"y\"), \" coordinate which means they are aligned horizontal but have different \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"x\"), \" coordinates. If they had the same \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"x\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"y\"), \" coordinate they would overlap with each other. The \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"viewBox\"), \" property in the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"<svg/>\"), \" that wraps these components determines how viewed in these shapes appear. Amelia Wattenberger created a great, interactive writeup for \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://wattenberger.com/guide/scaling-svg\"\n  }, \"getting a better  understanding of viewBox\"), \".\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-svg\"\n  }, \"<svg xmlns=\\\"http://www.w3.org/2000/svg\\\" viewBox=\\\"0 0 1728 500\\\">\\n    <rect x=\\\"153.55\\\" y=\\\"200\\\" width=\\\"300\\\" height=\\\"300\\\" fill=\\\"#ff499e\\\" />\\n  <rect x=\\\"519.55\\\" y=\\\"200\\\" width=\\\"300\\\" height=\\\"300\\\" fill=\\\"#99267e\\\" />\\n     <rect x=\\\"883.41\\\" y=\\\"200\\\" width=\\\"300\\\" height=\\\"300\\\" fill=\\\"#9c5ea8\\\" />\\n  <rect x=\\\"1263.41\\\" y=\\\"200\\\" width=\\\"300\\\" height=\\\"300\\\" fill=\\\"#798fd4\\\" />\\n</svg>\\n\")), mdx(\"p\", null, \"I've also written an article about my \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/blog/my-svg-creation-process\"\n  }, \"SVG creation process\"), \" for more complex SVGs.\"), mdx(\"h2\", {\n    \"id\": \"animating-svg-elements\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#animating-svg-elements\",\n    \"aria-label\": \"animating svg elements permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Animating SVG elements\"), mdx(\"p\", null, \"Since the visual properties of SVGs are written in a human readable format we can programmatically change different values of SVGs with CSS or JavaScript to create animations by applying a sequence of styling changes over a duration of time. \"), mdx(\"p\", null, \"Below is an example of a Bubble Tea SVG that I animated with CSS to make the cheeks blush and move the bubbles around a bit. You can take a peek at the SVG in the HTML tab of the Codepen below to see how I structured the SVG. You may notice that can group different elements in SVG with a \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"<g>\"), \" which functions similarly to \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"<div>\"), \"s and can be target programmatically if there is a specific \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"class\"), \" or \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"id\"), \" associated with a group. Individual SVG shapes and paths can also have their own unique identifiers if you want to target more specifically but so far I've found that it's helpful to animate in groups.\"), mdx(CodePen, {\n    codePenId: \"rNWwpVR\",\n    mdxType: \"CodePen\"\n  }), mdx(\"p\", null, \"The cheeks in the bubble tea SVG are grouped together with the id \\\"cheeks\\\"\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-svg\"\n  }, \"<g id=\\\"cheeks\\\" stroke=\\\"#de9bb5\\\" stroke-miterlimit=\\\"10\\\" stroke-width=\\\"10\\\">\\n\")), mdx(\"p\", null, \"There's a default fill and stroke color set for the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"#cheeks\"), \" based on the original color values in the SVG but we can use CSS to target the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"#cheeks\"), \" and change the colors with the below animation that change the color of its thick stroke by applying a blush \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"animation\"), \" every that last a duration of \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"4s\"), \" for an \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"infinite\"), \" amount of time. \"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-css\"\n  }, \"#cheeks {\\n  /* play the blush animation for 4s and repeat an infinite amount of times */\\n  animation: blush 4s infinite;\\n} \\n\")), mdx(\"p\", null, \"Generally, on production sites you'd want to have more control over \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"when\"), \" an animation is running so that it isn't running continuously as opposed to just when visible or necessary for performance reasons.\"), mdx(\"p\", null, \"The specifics for \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"blush\"), \" to change the fill color are then defined in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"@keyframes blush\")), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-css\"\n  }, \"@keyframes blush {\\n  50% {\\n     /* change from original fill color (defined in SVG)\\n    to #b7094c halfway through the animation */\\n    stroke: #b7094c; \\n  }\\n}\\n\")), mdx(\"p\", null, \"If you view the CodePen you can also see the separate \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"jiggle\"), \" animation instances that I applied to each of the individual \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"#boba\"), \" at different time points (offsetting the seconds measurement in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"animation: jiggle 5s infinite\"), \") with the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://developer.mozilla.org/en-US/docs/Web/CSS/transform\"\n  }, \"CSS transform property\"), \" which allows you to move, scale, rotate and more!\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-css\"\n  }, \"/* excerpt of applying the jiggle animation with different timing to different elements*/\\n#boba-two {\\n  -webkit-animation: jiggle 5s infinite;\\n  animation: jiggle 5s infinite;\\n}\\n#boba-three {\\n  -webkit-animation: jiggle 3s infinite;\\n  animation: jiggle 3s infinite;\\n}\\n\")), mdx(\"h2\", {\n    \"id\": \"cross-browser-compatibility\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#cross-browser-compatibility\",\n    \"aria-label\": \"cross browser compatibility permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Cross-Browser Compatibility\"), mdx(\"p\", null, \"You may have noticed some of the CSS in the code examples in this article have prefixe like \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"-webkit\"), \". These are \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://developer.mozilla.org/en-US/docs/Glossary/Vendor_Prefix\"\n  }, \"vendor prefixes\"), \" which allows developers to use newer features that aren't yet considered stable within a specific browser. You can use a website like: \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://autoprefixer.github.io/\"\n  }, \"https://autoprefixer.github.io/\"), \" or a PostCSS tool like \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/postcss/autoprefixer\"\n  }, \"https://github.com/postcss/autoprefixer\"), \" to automate adding these prefixes to your animations to ensure any more experimental features have as much cross-browser support as possible. In addition to using these vendor prefixing tools I'd recommend actually doing cross-browser testing for your animation work and being familiar with \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://caniuse.com/\"\n  }, \"Can I Use\"), \" which shows up-to-date information on browser compatibility for specific features.\"), mdx(\"p\", null, \"The CSS animation examples in this article are relatively simple but more complex animations can be created using similar principles with with CSS animations or with animation libraries like \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://greensock.com/\"\n  }, \"GreenSock Animation Platform (GSAP)\")));\n}\n;\nMDXContent.isMDXComponent = true;","tableOfContents":{"items":[{"url":"#reading-and-writing-svgs","title":"Reading and Writing SVGs"},{"url":"#animating-svg-elements","title":"Animating SVG elements"},{"url":"#cross-browser-compatibility","title":"Cross-Browser Compatibility"}]},"frontmatter":{"title":"Getting Started with SVG Animation","date":"April 13, 2021","description":"This is an article about the basics of SVG animation.","tags":["CSS","SVG","Animation","Design"]}},"allWebMentionEntry":{"edges":[]}},"pageContext":{"permalink":"https://www.aboutmonica.com/blog/getting-started-with-svg-animation/","slug":"/blog/getting-started-with-svg-animation/","prev":{"id":"0a53e3c0-7455-561b-82df-2961f6c0dec7","frontmatter":{"title":"My SVG Creation Process","category":["tutorial"],"date":"2021-04-13T04:58:13.499Z","slug":"my-svg-creation-process","tags":["SVG","design"],"redirects":null},"fields":{"slug":"/blog/my-svg-creation-process/"}},"next":{"id":"bafb6ea1-8b2e-5a8e-a33e-582ce59a1006","frontmatter":{"title":"Creating Protected Routes In NextJS With Supabase","category":["tutorial"],"date":"2021-03-13T23:27:48.599Z","slug":"creating-protected-routes-in-next-js-with-supabase","tags":["NextJS","Supabase"],"redirects":null},"fields":{"slug":"/blog/creating-protected-routes-in-next-js-with-supabase/"}}}},
    "staticQueryHashes": ["1977783444","764694655"]}