Class: AnimateIt::AnimatableBuilder

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

Overview

----- Per-element DSL ------------------------------------------------

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AnimatableBuilder

Returns a new instance of AnimatableBuilder.



96
97
98
99
# File 'lib/animate_it/animation.rb', line 96

def initialize(name)
  @name = name
  @properties = []
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



94
95
96
# File 'lib/animate_it/animation.rb', line 94

def properties
  @properties
end

Instance Method Details

#css(property, from:, during: nil, keyframes: nil, to: nil, unit: nil) ⇒ Object

Generic CSS property — when the named helpers (fade/slide/scale) don't cover what you need (max-height, height, color, etc.).



119
120
121
122
# File 'lib/animate_it/animation.rb', line 119

def css(property, from:, during: nil, keyframes: nil, to: nil, unit: nil)
  kf = build_keyframes(during, nil, nil, keyframes, from: from, to: to.nil? ? from : to)
  add_property(property, property, unit, from, kf)
end

#fade(during: nil, in: nil, out: nil, keyframes: nil, from: 0, to: 1) ⇒ Object

Opacity 0→1 over a frame range (or beat name, or keyframe hash).



102
103
104
105
# File 'lib/animate_it/animation.rb', line 102

def fade(during: nil, in: nil, out: nil, keyframes: nil, from: 0, to: 1)
  add_property(:opacity, :opacity, nil, from,
               build_keyframes(during, binding.local_variable_get(:in), out, keyframes, from: from, to: to))
end

#scale(during: nil, keyframes: nil, from: 1, to: 1.05) ⇒ Object



113
114
115
# File 'lib/animate_it/animation.rb', line 113

def scale(during: nil, keyframes: nil, from: 1, to: 1.05)
  add_property(:scale, :scale, nil, from, build_keyframes(during, nil, nil, keyframes, from: from, to: to))
end

#slide(during: nil, keyframes: nil, from: 16, to: 0, axis: :y, unit: "px") ⇒ Object

Vertical translate fromto over a frame range.



108
109
110
111
# File 'lib/animate_it/animation.rb', line 108

def slide(during: nil, keyframes: nil, from: 16, to: 0, axis: :y, unit: "px")
  css = axis == :y ? :translate_y : :translate_x
  add_property(css, css, unit, from, build_keyframes(during, nil, nil, keyframes, from: from, to: to))
end