Git Product home page Git Product logo

spinkit's Introduction

Simple loading spinners animated with CSS. See demo.

SpinKit uses CSS animations to create smooth and easily customizable animations. The goal is not to offer a solution that works in every browser—if you're supporting browsers that haven't implemented the CSS animation property (e.g. IE9 and below), you'll want to detect support for the animation property, and implement a fallback (see below.)

Usage

Grab the HTML and CSS for a spinner and include it in your project. Note that a hidden spinner (opacity: 0, or visibility: hidden) will still animate. After hiding a spinner, it's recommended to remove it from the DOM, set display: none or pause the animation by setting animation-play-state: paused.

Implementing a fallback spinner

An easy way to provide a fallback animation is to check for support for the animation property, and replace the spinner with a GIF if it's not supported.

Coffeescript

browserSupportsCSSProperty: (propertyName) ->
  elm = document.createElement 'div'
  propertyName = propertyName.toLowerCase()

  return true if (elm.style[propertyName] != undefined)
      
  propertyNameCapital = propertyName.charAt(0).toUpperCase() + propertyName.substr 1
  domPrefixes = 'Webkit Moz ms O'.split ' '

  for i in [0...domPrefixes.length]
    if (elm.style[domPrefixes[i] + propertyNameCapital] != undefined)
      return true

  false

Use it to check for animation support:

unless (@browserSupportsCSSProperty 'animation')
	# fallback…

Javascript

function browserSupportsCSSProperty(propertyName) {
  var elm = document.createElement('div');
  propertyName = propertyName.toLowerCase();

  if (elm.style[propertyName] != undefined)
  	return true;
      
  var propertyNameCapital = propertyName.charAt(0).toUpperCase() + propertyName.substr(1),
  	domPrefixes = 'Webkit Moz ms O'.split(' ');

  for (var i = 0; i < domPrefixes.length; i++) {
    if (elm.style[domPrefixes[i] + propertyNameCapital] != undefined)
      return true;
  }

  return false;
}

Use it to check for animation support:

if (!browserSupportsCSSProperty('animation')) {
	// fallback…
}

Contribution

If you're submitting a new animation, make sure that it looks identical in all browsers that support CSS animations.

spinkit's People

Contributors

tobiasahlin avatar mhm5000 avatar patrickjs avatar

Watchers

Dheeraj kumar avatar  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.