Home

# Class goog.dom.ViewportSizeMonitor

This class can be used to monitor changes in the viewport size. Instances dispatch a {@link goog.events.EventType.RESIZE} event when the viewport size changes. Handlers can call {@link goog.dom.ViewportSizeMonitor#getSize} to get the new viewport size. Use this class if you want to execute resize/reflow logic each time the user resizes the browser window. This class is guaranteed to only dispatch {@code RESIZE} events when the pixel dimensions of the viewport change. (Internet Explorer fires resize events if any element on the page is resized, even if the viewport dimensions are unchanged, which can lead to infinite resize loops.) Example usage:

    var vsm = new goog.dom.ViewportSizeMonitor();
    goog.events.listen(vsm, goog.events.EventType.RESIZE, function(e) {
    alert('Viewport size changed to ' + vsm.getSize());
    });

Manually verified on IE6, IE7, FF2, Opera 9, and WebKit. {@code getSize} doesn't always return the correct viewport height on Safari 2.0.4.extends goog.events.EventTarget

Instance Method Summary
| `checkForSizeChange_()` Measures the dimensions of the viewport and dispatches a {@link goog.events.EventType.RESIZE} event if the current dimensions are different from the previous ones.

`disposeInternal()`

Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:

    MyClass.prototype.disposeInternal = function() {
    MyClass.superClass_.disposeInternal.call(this);
    // Dispose logic for MyClass
    };

| `getSize() ⇒ ?goog.math.Size` Returns the most recently recorded size of the viewport, in pixels. May return null if no window resize event has been handled yet.
| `handleResize_(?goog.events.Event event)` Handles window resize events by measuring the dimensions of the viewport and dispatching a {@link goog.events.EventType.RESIZE} event if the current dimensions are different from the previous ones.
| `isPollingRequired_() ⇒ boolean` Checks if polling is required for this user agent. Opera only requires polling when the page is loaded within an IFRAME.

Static Method Summary
| `getInstanceForWindow(?Window= opt_window) ⇒ ?goog.dom.ViewportSizeMonitor` Returns a viewport size monitor for the given window. A new one is created if it doesn't exist already. This prevents the unnecessary creation of multiple spooling monitors for a window.