CanvasLoader Class
CanvasLoader is a JavaScript UI library that draws and animates circular preloaders using the Canvas HTML object.
A CanvasLoader instance creates two canvas elements which are placed into a placeholder div (the id of the div has to be passed in the constructor). The second canvas is invisible and used for caching purposes only.
If no id is passed in the constructor, the canvas objects are paced in the document directly.
Constructor
CanvasLoader
-
target -
[settings]
Parameters:
-
targetObjectThe target DOM element to place the spinner into
-
[settings]Object optionalSettings to customise the spinner instance
-
[diameter]Number optionalThe expected diameter
-
[density]Number optionalThe number of the shapes
-
[color]Number optionalThe color of the shapes
-
[range]Number optionalThe weight of the trail
-
[duration]Number optionalThe duration of 1 spin animation to completely go around
-
[shape]Number optionalThe shape type (oval, rect, square, roundRect)
-
[id]String optionalThe id of the CanvasLoader instance
-
Item Index
Methods
Methods
_draw
()
private
Draw the shapes on the canvas
_getDefaults
()
private
Return the default settings
_getRGB
-
color
Return the RGB values of the passed color
Parameters:
-
colorStringThe HEX color value to be converted to RGB
_init
-
target -
settings
Initialization method
Parameters:
-
targetObjectThe target DOM element to place the spinner into
-
settingsObjectSettings to customise the spinner instance
destruct
()
Clears the DOM and resets all params
get
-
key
Return argument value by key if defined
Parameters:
-
keyStringThe key to look up
Returns:
The value of the key
hide
()
CanvasLoader
chainable
Stops the rendering of the loader animation and hides the loader
Returns:
The CanvasLoader instance
proto._addElement
-
tag -
par -
opt
Creates a new element with the tag and applies the passed properties on it
Parameters:
-
tagStringThe tag to be created
-
parStringThe DOM element the new element will be appended to
-
optObjectAdditional properties passed to the new DOM element
Returns:
The DOM element
proto._setAttribute
-
el -
opt
Sets the attributes on the element
Parameters:
-
elObjectThe DOM element to add the attributes to
-
optObjectThe attributes
Returns:
The DOM element
proto._setCSS
-
el -
opt
Sets the css properties on the element
Parameters:
-
elObjectThe DOM element to be styled
-
optObjectThe style properties
Returns:
The DOM element
proto._supportsKeyframes
()
Boolean
private
Returns if the browser supports CSS animations
Returns:
proto._transformCachedCanvasContext
-
canvasContext -
x -
y -
rads
Transforms the cache canvas before drawing
Parameters:
-
canvasContextObjectThe canvas context to be transformed
-
xNumberx translation
-
yNumbery translation
-
radsNumberRotation in radians
show
()
CanvasLoader
chainable
Shows the rendering of the loader animation
Returns:
The CanvasLoader instance
Properties
_cacheCanvas
Object
private
The canvas we use for caching
_cacheContext
Object
private
The context of the cache canvas
_canvas
Object
private
The div we draw the shapes into
_color
String
private
The color of the loader shapes in HEX
Default: '#000000'
_colorRegEx
Object
private
Regular expression for matching Hexadecimal colour values
_container
Object
private
The div we place the canvas object into
_context
Object
private
The canvas context
_cRGB
Object
private
The color of the loader shapes in RGB
_currentDegree
Number
private
The current rotation degree of the spinner
_defaultSettings
Object
private
Holds default settings
_density
Number
private
The number of shapes drawn on the loader canvas
Default: 40
_diameter
Number
private
The diameter of the loader
Default: 40
_duration
Number
private
The duration of a 360 degree rotation in seconds
_range
Number
private
The amount of the modified shapes in percent.
_settings
Object
private
Holds settings (this is updated with user settings)
_shape
String
private
The type of the loader shapes
Default: 'oval'
_shapes
Object
private
The type of supported spinner shapes
_supportsCanvas
Boolean
private
Check for canvas support
_timer
Boolean
private
Adds a timer for the rendering
