Class: Browser::Window::View
Instance Method Summary collapse
- #height ⇒ Object
-
#initialize(window) ⇒ View
constructor
A new instance of View.
-
#on_zoom(&block) ⇒ Object
Handle #pixel_ratio changes.
- #width ⇒ Object
-
#zoom ⇒ Object
Get a device pixel ratio.
Constructor Details
#initialize(window) ⇒ View
Returns a new instance of View.
4 5 6 7 |
# File 'opal/browser/window/view.rb', line 4 def initialize(window) @window = window @native = window.to_n end |
Instance Method Details
#height ⇒ Object
14 15 16 |
# File 'opal/browser/window/view.rb', line 14 def height `#@native.innerHeight` end |
#on_zoom(&block) ⇒ Object
Handle #pixel_ratio changes. This will trigger a block on zoom.
43 44 45 46 47 48 |
# File 'opal/browser/window/view.rb', line 43 def on_zoom &block %x{ var mqString = "(resolution: " + #@native.devicePixelRatio + "dppx)"; #@native.matchMedia(mqString).addListener(#{block.to_n}); } end |
#width ⇒ Object
10 11 12 |
# File 'opal/browser/window/view.rb', line 10 def width `#@native.innerWidth` end |
#zoom ⇒ Object
Get a device pixel ratio. Can be used to handle desktop browser zoom, retina devices and custom screen scale for mobile devices. Use $window.visual_viewport.scale to handle mobile zoom.
38 39 40 |
# File 'opal/browser/window/view.rb', line 38 def zoom `#@native.devicePixelRatio` end |