Class: Dommy::KeyframeEffect

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/animation.rb

Overview

‘KeyframeEffect` — wraps a target element + keyframes + timing. Dommy doesn’t interpolate values (no layout / render); the effect is just a record of what the animation describes.

Spec: drafts.csswg.org/web-animations/#keyframeeffect

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, keyframes, options = nil) ⇒ KeyframeEffect

Returns a new instance of KeyframeEffect.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dommy/animation.rb', line 12

def initialize(target, keyframes, options = nil)
  @target = target
  @keyframes = case keyframes
  when nil
    []
  when Array
    keyframes
  else
    [keyframes]
  end

  @timing = normalize_timing(options)
end

Instance Attribute Details

#keyframesObject (readonly)

Returns the value of attribute keyframes.



10
11
12
# File 'lib/dommy/animation.rb', line 10

def keyframes
  @keyframes
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/dommy/animation.rb', line 10

def target
  @target
end

Instance Method Details

#__js_call__(method, args) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/dommy/animation.rb', line 51

def __js_call__(method, args)
  case method
  when "getTiming"
    get_timing
  when "updateTiming"
    update_timing(args[0] || {})
  end
end

#__js_get__(key) ⇒ Object



44
45
46
47
48
49
# File 'lib/dommy/animation.rb', line 44

def __js_get__(key)
  case key
  when "target"
    @target
  end
end

#duration_msObject



39
40
41
42
# File 'lib/dommy/animation.rb', line 39

def duration_ms
  d = @timing["duration"]
  d.is_a?(Numeric) ? d.to_i : 0
end

#get_timingObject Also known as: getTiming



26
27
28
# File 'lib/dommy/animation.rb', line 26

def get_timing
  @timing.dup
end

#update_timing(timing) ⇒ Object Also known as: updateTiming



32
33
34
35
# File 'lib/dommy/animation.rb', line 32

def update_timing(timing)
  @timing.merge!(timing.transform_keys(&:to_s))
  nil
end