Mastering SVG

Book description

Take the plunge and develop cross-browser-compatible and responsive web designs with SVG

Key Features

  • Master the art of custom animations and visualizations with SVG, CSS, and JavaScript
  • Combine SVG with third-party libraries and frameworks such as React, JQuery, D3, and Snap.svg for GUI-rich apps
  • Create an awesome user experience with high-performance graphics for your web applications

Book Description

SVG is the most powerful image format in use on the web. In addition to producing resolution-independent images for today's multi-device world, SVG allows you to create animations and visualizations to add to your sites and applications. The simplicity of cross-platform markup, mixed with familiar modern web languages, such as CSS and JavaScript, creates a winning combination for designers and developers alike.

In this book, you will learn how to author an SVG document using common SVG features, such as elements and attributes, and serve SVG on the web using simple configuration tips for common web servers. You will also use SVG elements and images in HTML documents.

Further, you will use SVG images for a variety of common tasks, such as manipulating SVG elements, adding animations using CSS, mastering the basic JavaScript SVG (API) using Document Object Model (DOM) methods, and interfacing SVG with common libraries and frameworks, such as React, jQuery, and Angular.

You will then build an understanding of the Snap.svg and SVG.js APIs, along with the basics of D3, and take a look at how to implement interesting visualizations using the library. By the end of the book, you will have mastered creating animations with SVG.

What you will learn

  • Deliver the elements that make up an SVG image
  • Replace your old CSS sprites with SVG
  • Understand animation and data visualization with SVG are explained in pure JavaScript and using common libraries
  • Use SVG to scale images across multiple devices easily
  • Harness the power of CSS animations and transformations to manipulate your SVG images in a replicable, remixable way
  • Interface SVG with common libraries and frameworks, such as jQuery, React, and Angular

Who this book is for

This book is for web developers and designers looking to add animation to their projects. Some experience with HTML, CSS, and JavaScript is required.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Mastering SVG
  3. PacktPub.com
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book.
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Introducing Scalable Vector Graphics
    1. Creating a simple SVG image
    2. Using SVG as a content image
    3. Drawing with code
      1. Scalable + vector graphics
    4. Using SVG in CSS
      1. Gradients in SVG
    5. Directly embedding SVG in an HTML document
    6. Feature detection and Modernizr
    7. Summary
  7. Getting Started with Authoring SVG
    1. Positioning in SVG
      1. viewBox and viewport in SVG
    2. Introducing paths
    3. More on basic shapes
      1. The line element
      2. The ellipse element
      3. The polygon element
      4. The polyline element
    4. More on fills and strokes
      1. stroke-dasharray
      2. stroke-dashoffset
      3. stroke-linecap
      4. stroke-linejoin
      5. stroke-opacity
      6. linearGradient and radialGradient
      7. The pattern element
    5. Authoring programs
    6. Summary
  8. Digging Deeper with SVG Authoring
    1. Transformations
      1. translate
      2. scale
      3. rotate
      4. skew
    2. Clipping and masking
      1. Clipping
      2. Masking
      3. Importing images into SVG
    3. Filters
    4. Serving SVG on the web
      1. Apache
      2. nginx
      3. IIS
    5. Summary
  9. Using SVG in HTML
    1. SVG, HTML, and accessibility
      1. SVG as an image src
      2. Inline SVG
    2. SVG and responsive web design
      1. The srcset attribute
      2. The srcset and sizes attributes
      3. The picture element
    3. Additional details on inline SVG in an HTML document
      1. Caching
      2. Complexity
        1. Authoring
        2. The Document Object Model
    4. Summary
  10. Working with SVG and CSS
    1. CSS background images
      1. Data URLs for SVG background images
    2. SVG sprites and icon sets
    3. Styling inline SVG
      1. Using common CSS properties to manipulate SVGs
        1. Basic font properties
        2. Text properties
        3. Miscellaneous CSS properties
      2. Using SVG-specific CSS properties to manipulate SVGs
        1. Color and painting properties
        2. Stroke properties
        3. Text properties
        4. Compositing properties
        5. Interactivity properties
      3. Styles in standalone SVG images
    4. Basic CSS animations and transitions with SVG
      1. CSS animations 
        1. Basic animation format
        2. Animating a clip path
        3. Animating multiple properties and assigning multiple animations to an element
        4. CSS transitions
    5. Summary
  11. JavaScript and SVG
    1. JavaScript Versions and tools
      1. JavaScript Versions
        1. ECMAScript 5
        2. ECMAScript 2015 
        3. TypeScript
      2. Tooling
    2. The DOM interface to SVG
      1. Initial exploration
      2. The SVG DOM manipulator 
    3. Summary
  12. Common JavaScript Libraries and SVG
    1. Manipulating SVG with jQuery
    2. Working with AngularJS and SVG
    3. Manipulating SVG with Angular
      1. Getting started with Angular
        1. Installing Node, npm, and Angular Cli
    4. Working with React and SVG
    5. Summary
  13. SVG Animation and Visualizations
    1. Creating an SVG data visualization
    2. General techniques for animating SVG
      1. Animating with pure JavaScript
      2. Animating with CSS
      3. Animating SVG with SMIL
      4. Animating SVG with Vivus
      5. Animating SVG with GSAP
    3. Summary
  14. Helper Libraries Snap.svg and SVG.js
    1. Working with Snap.svg
      1. Getting started with Snap.svg
      2. Animation with Snap
      3. Snap.svg utilities
      4. Snap.svg events
      5. Custom data visualization with Snap.svg
    2. Working with SVG.js
      1. Getting started with SVG.js
      2. Animation with SVG.js
      3. SVG.js utilities
      4. SVG.js events
      5. Custom data visualization with SVG.js
    3. Summary
  15. Working with D3.js
    1. Getting started with D3
      1. D3's enter and exit
    2. Implementing a donut chart with D3
    3. Implementing a chord diagram in D3
    4. Summary
  16. Tools to Optimize Your SVG
    1. Serving compressed SVG
      1. gzipping SVG on Apache
      2. SVG compression on nginx
      3. SVG compression on IIS
    2. SVGO
      1. SVGOMG
      2. SVGO authoring plugins
    3. svgcleaner
    4. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Mastering SVG
  • Author(s): Rob Larsen
  • Release date: September 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788626743