API Docs for: 0.9.1
Show:

CanvasLoader Class

Module: CanvasLoader

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:

  • target Object

    The target DOM element to place the spinner into

  • [settings] Object optional

    Settings to customise the spinner instance

    • [diameter] Number optional

      The expected diameter

    • [density] Number optional

      The number of the shapes

    • [color] Number optional

      The color of the shapes

    • [range] Number optional

      The weight of the trail

    • [duration] Number optional

      The duration of 1 spin animation to completely go around

    • [shape] Number optional

      The shape type (oval, rect, square, roundRect)

    • [id] String optional

      The id of the CanvasLoader instance

Methods

_draw

() private

Draw the shapes on the canvas

_getDefaults

() private

Return the default settings

_getRGB

(
  • color
)
private

Return the RGB values of the passed color

Parameters:

  • color String

    The HEX color value to be converted to RGB

_init

(
  • target
  • settings
)
private

Initialization method

Parameters:

  • target Object

    The target DOM element to place the spinner into

  • settings Object

    Settings to customise the spinner instance

destruct

()

Clears the DOM and resets all params

get

(
  • key
)

Return argument value by key if defined

Parameters:

  • key String

    The 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:

CanvasLoader:

The CanvasLoader instance

proto._addElement

(
  • tag
  • par
  • opt
)
Object private

Creates a new element with the tag and applies the passed properties on it

Parameters:

  • tag String

    The tag to be created

  • par String

    The DOM element the new element will be appended to

  • opt Object

    Additional properties passed to the new DOM element

Returns:

Object:

The DOM element

proto._setAttribute

(
  • el
  • opt
)
Object private

Sets the attributes on the element

Parameters:

  • el Object

    The DOM element to add the attributes to

  • opt Object

    The attributes

Returns:

Object:

The DOM element

proto._setCSS

(
  • el
  • opt
)
Object private

Sets the css properties on the element

Parameters:

  • el Object

    The DOM element to be styled

  • opt Object

    The style properties

Returns:

Object:

The DOM element

proto._supportsKeyframes

() Boolean private

Returns if the browser supports CSS animations

Returns:

Boolean:

proto._transformCachedCanvasContext

(
  • canvasContext
  • x
  • y
  • rads
)
private

Transforms the cache canvas before drawing

Parameters:

  • canvasContext Object

    The canvas context to be transformed

  • x Number

    x translation

  • y Number

    y translation

  • rads Number

    Rotation in radians

show

() CanvasLoader chainable

Shows the rendering of the loader animation

Returns:

CanvasLoader:

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