Module: DOM::Dimensions

Included in:
Element
Defined in:
opal/fron/dom/modules/dimensions.rb

Overview

Dimensions module for returning node like elements position on the screen.

Features:

  • Accessors for top, left, right, bottom, width and height

  • Positions are compensated with scroll position

Instance Method Summary collapse

Instance Method Details

#bottomNumber

Returns the bottom position of the element


34
35
36
# File 'opal/fron/dom/modules/dimensions.rb', line 34

def bottom
  `#{clientRect}.bottom` + Window.scrollY
end

#clientRectHash (private)

Gets the bounding client rect of element.


80
81
82
# File 'opal/fron/dom/modules/dimensions.rb', line 80

def clientRect
  `#{@el}.getBoundingClientRect()`
end

#cover?(pos) ⇒ Boolean

Returns whether or not the element covers the given position


71
72
73
# File 'opal/fron/dom/modules/dimensions.rb', line 71

def cover?(pos)
  (left...(left + width)).cover?(pos.x) && (top...(top + height)).cover?(pos.y)
end

#heightNumber

Returns the height of the element


48
49
50
# File 'opal/fron/dom/modules/dimensions.rb', line 48

def height
  `#{clientRect}.height`
end

#leftNumber

Returns the left position of the element


20
21
22
# File 'opal/fron/dom/modules/dimensions.rb', line 20

def left
  `#{clientRect}.left` + Window.scrollX
end

#rightNumber

Returns the right position of the element


27
28
29
# File 'opal/fron/dom/modules/dimensions.rb', line 27

def right
  `#{clientRect}.right` + Window.scrollX
end

#scrollLeftNumber

Returns the left scroll position of the element


62
63
64
# File 'opal/fron/dom/modules/dimensions.rb', line 62

def scrollLeft
  `#{@el}.scrollLeft`
end

#scrollTopNumber

Returns the top scroll position of the element


55
56
57
# File 'opal/fron/dom/modules/dimensions.rb', line 55

def scrollTop
  `#{@el}.scrollTop`
end

#topNumber

Returns the top position of the element


13
14
15
# File 'opal/fron/dom/modules/dimensions.rb', line 13

def top
  `#{clientRect}.top` + Window.scrollY
end

#widthNumber

Returns the width of the element


41
42
43
# File 'opal/fron/dom/modules/dimensions.rb', line 41

def width
  `#{clientRect}.width`
end