Use SVG to Create an Animatable Cross

Jhey Tompkins
InstructorJhey Tompkins
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

We can use SVG to create a cross with one path. But, what if want to animate a cross as if it's being hand-drawn? We can do this by defining more than one path for our SVG.

Instructor: [0:00] Our tic-tac-toe board has naughts, but now it needs crosses. To do this, we can convert our X element overlay to an SVG. We can set a viewBox of " 100 100," and let's remove the text content.

[0:14] We could use a single path to draw a cross. In our case, we want to animate the cross as if it's being drawn by hand, so we're going to use two paths. For our first path, we move to position 80,20. Then, we draw a line to 20,80. We can give that a stroke of "black". If we check in the browser, that gives us this diagonal line.

[0:36] For our second path, we're going to start by moving to 20,20. Then, we're going to draw a line to 80,80. This will also have a stroke of "black".

[0:48] If we check the demo, we now have a cross. We can proceed to give it a matching stroke-width and linecap, and that gives us a cross.

[0:57] In review, we can use SVG to draw a cross, where we use multiple paths to draw a cross instead of a single path, because we're mindful of how we might like to animate that cross.

egghead
egghead
~ 14 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today