Ajax Loader
×
HTML
.bigSpinner.useSpinner
1
.bigSpinner.useSpinner
 
CSS
.bigSpinner
1
.bigSpinner
2
  background-image: -webkit-canvas(spinner)
3
 
4
.useSpinner
5
  background-position: center 70%
6
  background-repeat: no-repeat
7
  width: 100%
8
  min-height: 100%
9
  padding-top: 20%
10
  -webkit-box-sizing: border-box
11
  text-align: center
12
  font-size: 100px
13
 
14
 
 
JavaScript
# It's fork from http://cssdeck.com/labs/vvt7yt0d
1
# It's fork from http://cssdeck.com/labs/vvt7yt0d
2
class BigSpinner
3
  constructor: (id, color, shadow) ->
4
    @ctx = document.getCSSCanvasContext("2d", id, 37, 37)
5
    @ctx.lineWidth = 3
6
    @ctx.lineCap = "round"
7
    @ctx.strokeStyle = color
8
    if shadow
9
      @ctx.shadowOffsetX = 1
10
      @ctx.shadowOffsetY = 1
11
      @ctx.shadowBlur = 1
12
      @ctx.shadowColor = shadow
13
    @step = 0
14
    @timer = null
15
    return @
16
 
17
  stop: ->
18
    if @timer
19
      @ctx.clearRect 0, 0, 37, 37
20
      clearInterval @timer
21
      @timer = null
22
    @
23
 
24
  start: ->
25
    return @ if @timer
26
    # 24-30 fps good idea! 
27
    # It will be smooth :)
28
    # And cool trick, bind.
29
    @timer = setInterval(draw.bind(@), 1000 / 24)
30
    @
31
 
32
  draw = ->
33
    @ctx.clearRect 0, 0, 37, 37
34
    @ctx.save()
35
    @ctx.translate 18, 18
36
    @ctx.rotate @step * Math.PI / 180
37
    i = 0
38
  
39
    while i < 12
40
      @ctx.rotate 30 * Math.PI / 180
41
      drawLine @ctx, i
42
      i++
43
    @ctx.restore()
44
    @step += 30
45
    @step = 0  if @step is 360
46
 
47
  drawLine = (ctx, i) ->
48
    ctx.beginPath()
49
    ctx.globalAlpha = i / 12
50
    ctx.moveTo 0, 8 + 1
51
    ctx.lineTo 0, 16 - 1
52
    ctx.stroke()
53
    ctx
54
    
55
 
56
spinner = new BigSpinner("spinner", "#666").start()
57
# Or
58
#spinner = new BigSpinner("spinner", "#666")
59
#spinner.start()
60
# Do work
61
#spinner.stop()
 

Untitled

CSSDeck G+