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
permalink #initialize(window) ⇒ View
Returns a new instance of View.
5 6 7 8 |
# File 'opal/browser/window/view.rb', line 5 def initialize(window) @window = window @native = window.to_n end |
Instance Method Details
permalink #height ⇒ Object
15 16 17 |
# File 'opal/browser/window/view.rb', line 15 def height `#@native.innerHeight` end |
permalink #on_zoom(&block) ⇒ Object
Handle #pixel_ratio changes. This will trigger a block on zoom.
44 45 46 47 48 49 |
# File 'opal/browser/window/view.rb', line 44 def on_zoom &block %x{ var mqString = "(resolution: " + #@native.devicePixelRatio + "dppx)"; #@native.matchMedia(mqString).addListener(#{block.to_n}); } end |
permalink #width ⇒ Object
11 12 13 |
# File 'opal/browser/window/view.rb', line 11 def width `#@native.innerWidth` end |
permalink #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.
39 40 41 |
# File 'opal/browser/window/view.rb', line 39 def zoom `#@native.devicePixelRatio` end |