Class: Watir::Browser::Scroll
- Inherits:
-
Object
- Object
- Watir::Browser::Scroll
- Defined in:
- lib/watir-scroll/browser/scroll.rb
Instance Method Summary collapse
-
#by(left, top) ⇒ Object
Scrolls by offset.
-
#initialize(browser) ⇒ Scroll
constructor
A new instance of Scroll.
-
#to(param) ⇒ Object
Scrolls to position.
Constructor Details
#initialize(browser) ⇒ Scroll
Returns a new instance of Scroll.
5 6 7 |
# File 'lib/watir-scroll/browser/scroll.rb', line 5 def initialize(browser) @browser = browser end |
Instance Method Details
#by(left, top) ⇒ Object
Scrolls by offset.
36 37 38 39 |
# File 'lib/watir-scroll/browser/scroll.rb', line 36 def by(left, top) @browser.execute_script('window.scrollBy(arguments[0], arguments[1]);', Integer(left), Integer(top)) self end |
#to(param) ⇒ Object
Scrolls to position.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/watir-scroll/browser/scroll.rb', line 13 def to(param) args = case param when :top, :start 'window.scrollTo(0, 0);' when :center 'window.scrollTo(window.outerWidth / 2, window.outerHeight / 2);' when :bottom, :end 'window.scrollTo(0, document.body.scrollHeight);' when Array ['window.scrollTo(arguments[0], arguments[1]);', Integer(param[0]), Integer(param[1])] else raise ArgumentError, "Don't know how to scroll to: #{param}!" end @browser.execute_script(*args) self end |