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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



4
5
6
# File 'opal/browser/dom/element/scroll.rb', line 4

def element
  @element
end

#heightInteger (readonly)

Returns the height of the scroll.

Returns:

  • (Integer)

    the height of the scroll



83
84
85
# File 'opal/browser/dom/element/scroll.rb', line 83

def height
  `#@native.scrollHeight`
end

#widthInteger (readonly)

Returns the width of the scroll.

Returns:

  • (Integer)

    the width of the scroll



89
90
91
# File 'opal/browser/dom/element/scroll.rb', line 89

def width
  `#@native.scrollWidth`
end

#xInteger (readonly)

Returns the scroll position on the x axis.

Returns:

  • (Integer)

    the scroll position on the x axis



71
72
73
# File 'opal/browser/dom/element/scroll.rb', line 71

def x
  position.x
end

#yInteger (readonly)

Returns the scroll position on the y axis.

Returns:

  • (Integer)

    the scroll position on the y axis



77
78
79
# File 'opal/browser/dom/element/scroll.rb', line 77

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



108
109
110
111
112
113
114
115
116
117
118
119
# File 'opal/browser/dom/element/scroll.rb', line 108

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

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

  self
end

#positionObject

Raises:

  • (NotImplementedError)


25
26
27
# File 'opal/browser/dom/element/scroll.rb', line 25

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

#to(x, y) ⇒ Object #to(hash) ⇒ 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

Raises:

  • (NotImplementedError)


60
61
62
63
64
65
66
67
68
69
70
# File 'opal/browser/dom/element/scroll.rb', line 60

def to(*args)
  if Hash === args.first
    x = args.first[:x] || self.x
    y = args.first[:y] || self.y
  else
    x, y = args
  end

  `#@native.scrollTop  = #{y}`
  `#@native.scrollLeft = #{x}`
end

#to!(align = true) ⇒ Object



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

def to!(align = true)
  `#@native.scrollIntoView(align)`
end