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.



8
9
10
# File 'opal/browser/dom/element/scroll.rb', line 8

def element
  @element
end

#heightInteger (readonly)

Returns the height of the scroll.

Returns:

  • (Integer)

    the height of the scroll



144
145
146
# File 'opal/browser/dom/element/scroll.rb', line 144

def height
  `#@scrolling_native.scrollHeight`
end

#widthInteger (readonly)

Returns the width of the scroll.

Returns:

  • (Integer)

    the width of the scroll



150
151
152
# File 'opal/browser/dom/element/scroll.rb', line 150

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



132
133
134
# File 'opal/browser/dom/element/scroll.rb', line 132

def x
  position.x
end

#yInteger (readonly)

Returns the scroll position on the y axis.

Returns:

  • (Integer)

    the scroll position on the y axis



138
139
140
# File 'opal/browser/dom/element/scroll.rb', line 138

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



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

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)


160
161
162
# File 'opal/browser/dom/element/scroll.rb', line 160

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

#into_view!(align = true) ⇒ Object



165
166
167
# File 'opal/browser/dom/element/scroll.rb', line 165

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

#positionObject

Raises:

  • (NotImplementedError)


117
118
119
# File 'opal/browser/dom/element/scroll.rb', line 117

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



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

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