GithubHelp home page GithubHelp logo

modulexcite / svg-spinner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from micmro/svg-spinner

0.0 1.0 0.0 186 KB

Themeable SVG loading spinner using CSS animation.

JavaScript 23.85% HTML 76.15%

svg-spinner's Introduction

Themeable and cachable animated SVG loading spinner

It is only downloads one version of the SVG, stores in localStorage (when available), and colours it based on the data-colour attribute in the holder element. This way the browser only requests the spinner once (the one used here is 2.2kb gzip, including the CSS animation).

It still needs some JS for feature detection, fetch the SVG, inject the colour informantions and for the non-css-transformation fallback. I've used jQuery here, since I use it in most projects, but you can easily switch it to vanilla JavaScript.

<div class="load-spinner" data-colour="#fdbc33" data-fallback-class="no-svg-fallback-orange"></div>

Browser Support

Tested in: IE8**, IE9*, IE10, IE11, FF 33, Chrome 38, Opera 26, Safari 6.1, Safari 8, Android 4, Android 4.4, iOS 8

* Spinner falls back to JS animation as fallback for browser, like IE9, that don't support CSS animation - update this animation if you use a differnt style.

** Spinner falls back to gif in IE8 and other browsers that don't support SVG and/or the object tag.

Changing the colour

Change the data-colour="#fdbc33" attribute and update data-fallback-class="no-svg-fallback-orange" to switch the class IE8 uses as a fallback.

Reason for this approach

An inline svg tag is not beeing cached seperatly, an SVG in an img tag can only be animated with SMIL and that's not supported in IE yet.

So I initially used the object tag to load the SVG, which was nice, since it was fully self contained (including CSS and JS), but unfortunatly all browser cache each instance seperatly. Additionally even when the type is defined, IE is first issuing a HEAD request to determin the content-type, which adds another round trip to this sollution.

svg-spinner's People

Contributors

micmro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.