Class: Browser::DOM::Element::Scroll

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

Overview

TODO:

Consider using the new interfaces which allow for optional smooth transitions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element


6
7
8
# File 'opal/browser/dom/element/scroll.rb', line 6

def element
  @element
end

#heightInteger (readonly)

Returns the height of the scroll.

Returns:

  • (Integer)

    the height of the scroll


142
143
144
# File 'opal/browser/dom/element/scroll.rb', line 142

def height
  `#@scrolling_native.scrollHeight`
end

#widthInteger (readonly)

Returns the width of the scroll.

Returns:

  • (Integer)

    the width of the scroll


148
149
150
# File 'opal/browser/dom/element/scroll.rb', line 148

def width
  `#@scrolling_native.scrollWidth`
end

#xInteger (readonly)

Returns the scroll position on the x axis.

Returns:

  • (Integer)

    the scroll position on the x axis


130
131
132
# File 'opal/browser/dom/element/scroll.rb', line 130

def x
  position.x
end

#yInteger (readonly)

Returns the scroll position on the y axis.

Returns:

  • (Integer)

    the scroll position on the y axis


136
137
138
# File 'opal/browser/dom/element/scroll.rb', line 136

def y
  position.y
end

Instance Method Details

#by(x, y) ⇒ Object #by(hash) ⇒ Object

Overloads:

  • #by(x, y) ⇒ Object

    Scroll by the given x and y.

    Parameters:

    • x (Integer)

      scroll by x on the x axis

    • y (Integer)

      scroll by y on the y axis

  • #by(hash) ⇒ Object

    Scroll by the given x and y.

    Parameters:

    • hash (Hash)

      the descriptor

    Options Hash (hash):

    • :x (Integer)

      scroll by x on the x axis

    • :y (Integer)

      scroll by y on the y axis


85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'opal/browser/dom/element/scroll.rb', line 85

def by(*args)
  case args.first
  when Hash
    x = args.first[:x] || 0
    y = args.first[:y] || 0
  else
    x, y = args
  end

  set_by(x, y)

  self
end

#into_view(align = true) ⇒ Object

Non-standard. Not supported by modern Firefox. Use #into_view!

Raises:

  • (NotImplementedError)

158
159
160
# File 'opal/browser/dom/element/scroll.rb', line 158

def into_view(align = true)
  `#@scrolling_native.scrollIntoViewIfNeeded(align)`
end

#into_view!(align = true) ⇒ Object


163
164
165
# File 'opal/browser/dom/element/scroll.rb', line 163

def into_view!(align = true)
  `#@scrolling_native.scrollIntoView(align)`
end

#positionObject

Raises:

  • (NotImplementedError)

115
116
117
# File 'opal/browser/dom/element/scroll.rb', line 115

def position
  Browser::Position.new(`#@scrolling_native.scrollLeft`, `#@scrolling_native.scrollTop`)
end

#to(x, y) ⇒ Object #to(hash) ⇒ Object #to(symbol) ⇒ Object

Overloads:

  • #to(x, y) ⇒ Object

    Scroll to the given x and y.

    Parameters:

    • x (Integer)

      scroll to x on the x axis

    • y (Integer)

      scroll to y on the y axis

  • #to(hash) ⇒ Object

    Scroll to the given x and y.

    Parameters:

    • hash (Hash)

      the descriptor

    Options Hash (hash):

    • :x (Integer)

      scroll to x on the x axis

    • :y (Integer)

      scroll to y on the y axis

  • #to(symbol) ⇒ Object

    Scroll to :top or to :bottom

    Parameters:

    • symbol (Symbol)

      either :top or :bottom


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'opal/browser/dom/element/scroll.rb', line 51

def to(*args)
  x, y = nil, nil
  case args.first
  when Hash
    x = args.first[:x]
    y = args.first[:y]
  when :top
    y = 0
  when :bottom
    y = 99999999
  else
    x, y = args
  end

  set(x, y) if x || y

  self
end