Class: Shellfie::AnimationScrollEasing

Inherits:
Object
  • Object
show all
Defined in:
lib/shellfie/animation_scroll_easing.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ AnimationScrollEasing

Returns a new instance of AnimationScrollEasing.



5
6
7
# File 'lib/shellfie/animation_scroll_easing.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#output_delay(base_delay, index, total) ⇒ Object



9
10
11
12
13
14
# File 'lib/shellfie/animation_scroll_easing.rb', line 9

def output_delay(base_delay, index, total)
  return base_delay if total <= 1 || easing == "linear"

  progress = index.to_f / (total - 1)
  [(base_delay * delay_factor(progress)).round, 1].max
end

#transition_frames(lines, delay:, previous_count:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shellfie/animation_scroll_easing.rb', line 16

def transition_frames(lines, delay:, previous_count:)
  return [{ lines: lines, delay: delay }] unless scroll_transition?(delay, previous_count)

  delays = split_delay(delay, scroll_frame_count(delay))
  delays.each_with_index.map do |frame_delay, index|
    progress = (index + 1).to_f / delays.size
    {
      lines: lines,
      delay: frame_delay,
      window: { scroll_offset: scroll_progress(progress) }
    }
  end
end