API Docs for: 1.0.0
Show:

CanvasLoader Class

Defined in: src/hcl-1.0.0.js:37
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]
)

Defined in src/hcl-1.0.0.js:37

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

    • [speed] Number optional

      The speed

    • [fps] Number optional

      The FPS

    • [shape] Number optional

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

    • [id] String optional

      The id of the CanvasLoader instance

    • [safeVML] Boolean optional

      Whether or not density should be capped in IE

Methods

_addEl

(
  • tag
  • par
  • opt
)
Object private

Defined in src/hcl-1.0.0.js:62

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

_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

_setAttr

(
  • el
  • opt
)
Object private

Defined in src/hcl-1.0.0.js:96

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

_setCSS

(
  • el
  • opt
)
Object private

Defined in src/hcl-1.0.0.js:83

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

_tick

() private

Renders the loader animation

_transCon

(
  • x
  • x
  • y
  • r
)
private

Transforms the cache canvas before drawing

Parameters:

  • x Object

    The canvas context to be transformed

  • x Number

    x translation

  • y Number

    y translation

  • r Number

    Rotation radians

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

show

() CanvasLoader chainable

Shows the rendering of the loader animation

Returns:

CanvasLoader:

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