Demo
About
AjaxLoader library allows to create spinning activity indicators dynamically. It can be used instead of GIF image ajaxloaders. The main features of this library are the following:
- Easy to use
- No external images, dependencies or CSS files
- Very small size (only 1.8 kB)
- Resolution independent
- Cross-browser
- Free to use
How to use
AjaxLoader.js can be added to your site in three simple steps:
-
Include
ajaxloader.js
(or the minified versionajaxloader.min.js
for production) in your page. For example:<script src="../ajaxloader.js"></script>
-
Add to your page
canvas
object and setid
.<canvas id="spinner"></canvas>
-
Create
AjaxLoader
object and call functionshow()
:var ajaxLoader = new AjaxLoader("spinner");
You can specify options of the spinner before it's creation. For example:
ajaxLoader.show();var opts = { size: 32, // Width and height of the spinner factor: 0.25, // Factor of thickness, density, etc. color: "#000", // Color #rgb or #rrggbb speed: 1.0, // Number of turns per second clockwise: true // Direction of rotation }; var ajaxLoader = new AjaxLoader("spinner", opts); ajaxLoader.show();
API
<Object> AjaxLoader(id, [options])
Constructor returns AjaxLoader
object.
id <String>
The id of the canvas tag.-
[options] <Object>
Optional parameters of the spinner. Options object may contain some of these fields:size <Number>
Width and height of the spinner in pixels. The default value is 32.factor <Number>
Factor of thickness, density. The default value is 0.25.color <String>
Color #rgb or #rrggbb. The default value is black "#000".speed <Number>
Number of turns per second. The default value is 1.0.clockwise <Boolean>
Direction of rotation. The default value istrue
.
Examples:
var ajaxLoader = new AjaxLoader("spinner");
var ajaxLoader = new AjaxLoader("spinner", { color: "#FF00FF" });
<void> show()
Show the spinner and begin animation. Note: keyword void
uses instead of undefined
.
<void> hide()
Stop animation and hide the spinner. The element still remains in the DOM and you can show spinner again.
<Number> getSize()
Returns the size of the loader. The default value is 32.
<Number> getFactor()
Returns the thickness of the loader. The default value is 0.25.
<Number> getSpeed()
Returns the number of turns per second. The default value is 1.0.
<String> getColor()
Returns hexadecimal color of the loader. The default value is "#000"
(black).
<String> getClockwise()
Returns direction of the rotation. The default value is true
.
<void> setSize(value)
Sets the size of the loader.
Parameters:value <Number>
New size in pixels.
<void> setFactor(value)
Sets the thickness of the loader.
Parameters:value <Number>
New thickness in the range 0..1.
<void> setSpeed(value)
Sets turns count of the loader per second. Recommended to set the value in the range 0..3.0
Parameters:value <Number>
New speed.
<void> setColor(value)
Sets hexadecimal color of the loader.
Parameters:value <String>
New color in format"#rgb"
or"#rrggbb"
.
<void> setClockwise(value)
Sets direction of the rotation of your loader.
Parameters:value <Boolean>
New direction of the rotation.
Supported browsers
AjaxLoader supports the following browsers:
- Chrome 26.0+
- Firefox 20.0+
- Internet Explorer 10+
- Opera 12.0+
- Safari 6.0+
Release History
Version 0.1 (14.04.2013)
- Initial release
Contacts
If you find any bugs or have some suggestions, please use the GitHub issue tracker.You can also leave a comment. Follow me to GitHub.
If you have any questions write me to musicvano@gmail.com
For grateful users and those who want to support the development of this project:
License
Copyright (c) 2013 by Ivan Muzyka
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.