Class: Browser::Window::Scroll

Inherits:
Object
  • Object
show all
Defined in:
opal/browser/window/scroll.rb

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ Scroll

Returns a new instance of Scroll.



4
5
6
7
# File 'opal/browser/window/scroll.rb', line 4

def initialize(window)
  @window = window
  @native = window.to_n
end

Instance Method Details

#by(what) ⇒ Object



49
50
51
52
53
54
55
56
# File 'opal/browser/window/scroll.rb', line 49

def by(what)
  x = what[:x] || 0
  y = what[:y] || 0

  `#@native.scrollBy(#{x}, #{y})`

  self
end

#positionObject

Raises:

  • (NotImplementedError)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'opal/browser/window/scroll.rb', line 10

def position
  %x{
    var doc  = #@native.document,
        root = doc.documentElement,
        body = doc.body;

    var x = root.scrollLeft || body.scrollLeft,
        y = root.scrollTop  || body.scrollTop;
  }

  Position.new(`x`, `y`)
end

#to(what) ⇒ Object



40
41
42
43
44
45
46
47
# File 'opal/browser/window/scroll.rb', line 40

def to(what)
  x   = what[:x] || self.x
  y   = what[:y] || self.y

  `#@native.scrollTo(#{x}, #{y})`

  self
end

#xObject



32
33
34
# File 'opal/browser/window/scroll.rb', line 32

def x
  position.x
end

#yObject



36
37
38
# File 'opal/browser/window/scroll.rb', line 36

def y
  position.y
end