Features:
1. No image, no external CSS
2. No dependency (jQuery supported, but not required)
3. configurable height
4. Resolution independence
5. VML is supported when the earlier version of IE is not supported.
6. Use the Key Frame Animation and setTimeout ()
7. compatible with various mainstream browsers, including IE6
8. MIT Authentication
Spin. js dynamically creates a progress bar, which can be replaced by loading GIF images using ajax.
<Body> <div id = "myspin"> </div> <script src = "spin. js "> </script> <script> var opts = {lines: 13, // Number of drawn lines length: 20, // length of each line width: 10, // width radius: 30, // the radius of the rounded Corner of the line corners: 1, // Corner roundness (0 .. 1) rotate: 0, // rotation offset direction: 1, // 1: clockwise,-1: counterclockwise color: '#000 ', // # rgb or # rrggbb or array of colors speed: 1, // speed/second trail: 60, // Afterglow percentage shadow: false, // whether to display shadow hwaccel: false, // whether or not to use hardware acceleration className: 'scheduler', // The class name zIndex: 2e9 bound to the spinner, // The positioning layer (default: 2000000000) top: 'auto', // located relative to the parent element, unit: px left: 'auto' // left positioned relative to the parent element, unit: px}; var target = document. getElementById ("myspin"); var spinner = new Spinner (opts ). spin (target) </script> </body> <div id = "myspin"> </div> <script src = "spin. js "> </script> <script> var opts = {lines: 13, // Number of drawn lines length: 20, // length of each line width: 10, // width radius: 30, // the radius of the rounded Corner of the line corners: 1, // Corner roundness (0 .. 1) rotate: 0, // rotation offset direction: 1, // 1: clockwise,-1: counterclockwise color: '#000 ', // # rgb or # rrggbb or array of colors speed: 1, // speed/second trail: 60, // Afterglow percentage shadow: false, // whether to display shadow hwaccel: false, // whether or not to use hardware acceleration className: 'scheduler', // The class name zIndex: 2e9 bound to the spinner, // The positioning layer (default: 2000000000) top: 'auto', // located relative to the parent element, unit: px left: 'auto' // left positioned relative to the parent element, unit: px}; var target = document. getElementById ("myspin"); var spinner = new Spinner (opts ). spin (target) </script> </body>
The spin () method initializes the necessary HTML elements and starts the animation. If the target element is passed as a parameter, the spinner is taken as the first
Child node, added to the parent node, horizontally and vertically centered.
Manual positioning:
The default value is horizontal and vertical center. We can manually configure the top and left in the initialization parameter to locate the target element.
To manually insert a spinner to a DOM node, call the spin () method without any parameters. Use the el attribute to access HTML elements. As follows:
Var spinner = new Spinner (). spin ();
Target. appendChild (spinner. el );
The returned result is a relatively positioned DIV [class = "spinner"] element with a height of 0. The center of the spinner is located in the upper left corner of the div.