Class: Browser::DOM::Element::Position
- Defined in:
- lib/diamonds/opal/browser/dom/element/position.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#x ⇒ Integer
readonly
The position of the element on the x axis.
-
#y ⇒ Integer
readonly
The position of the element on the y axis.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(element) ⇒ Position
constructor
A new instance of Position.
Constructor Details
#initialize(element) ⇒ Position
Returns a new instance of Position.
7 8 9 10 |
# File 'lib/diamonds/opal/browser/dom/element/position.rb', line 7 def initialize(element) @element = element @native = element.to_n end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
4 5 6 |
# File 'lib/diamonds/opal/browser/dom/element/position.rb', line 4 def element @element end |
#x ⇒ Integer (readonly)
Returns the position of the element on the x axis.
35 36 37 |
# File 'lib/diamonds/opal/browser/dom/element/position.rb', line 35 def x get.x end |
#y ⇒ Integer (readonly)
Returns the position of the element on the y axis.
41 42 43 |
# File 'lib/diamonds/opal/browser/dom/element/position.rb', line 41 def y get.y end |
Instance Method Details
#get ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/diamonds/opal/browser/dom/element/position.rb', line 13 def get offset = @element.offset position = offset.get parent = offset.parent parent_offset = Browser::Position.new(0, 0) if @element.style[:position] == :fixed unless parent =~ :html parent_offset = parent.offset end parent_offset.x += parent.style['border-top-width'].to_i parent_offset.y += parent.style['border-left-width'].to_i end Browser::Position.new( position.x - parent_offset.x - @element.style['margin-left'].to_i, position.y - parent_offset.y - @element.style['margin-top'].to_i) end |