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
-
[speed]Number optionalThe speed
-
[fps]Number optionalThe FPS
-
[shape]Number optionalThe shape type (oval, rect, square, roundRect)
-
[id]String optionalThe id of the CanvasLoader instance
-
[safeVML]Boolean optionalWhether or not density should be capped in IE
-
Item Index
Methods
Methods
_addEl
-
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
_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
_setAttr
-
el -
opt
Sets the attributes on the element
Parameters:
-
elObjectThe DOM element to add the attributes to
-
optObjectThe attributes
Returns:
The DOM element
_setCSS
-
el -
opt
Sets the css properties on the element
Parameters:
-
elObjectThe DOM element to be styled
-
optObjectThe style properties
Returns:
The DOM element
_tick
()
private
Renders the loader animation
_transCon
-
x -
x -
y -
r
Transforms the cache canvas before drawing
Parameters:
-
xObjectThe canvas context to be transformed
-
xNumberx translation
-
yNumbery translation
-
rNumberRotation radians
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
show
()
CanvasLoader
chainable
Shows the rendering of the loader animation
Returns:
The CanvasLoader instance
Properties
_can
Object
private
The div we draw the shapes into
_cCan
Object
private
The canvas we use for caching
_cCon
Object
private
The context of the cache canvas
_color
String
private
The color of the loader shapes in HEX
Default: "#000000"
_con
Object
private
The canvas context
_cont
Object
private
The div we place the canvas object into
_cRGB
Object
private
The color of the loader shapes in RGB
_currentId
Number
private
The active shape id for rendering
_density
Number
private
The number of shapes drawn on the loader canvas
Default: 40
_diameter
Number
private
The diameter of the loader
Default: 40
_fps
Number
private
The FPS value of the loader animation rendering
_range
Number
private
The amount of the modified shapes in percent.
_shape
String
private
The type of the loader shapes
Default: "oval"
_speed
Number
private
The speed of the loader animation
_timer
Boolean
private
Adds a timer for the rendering
