1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>goog.dom.ViewportSizeMonitor</title>
<script src="../base.js"></script>
<script>
goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.math.Size');
goog.require('goog.style');
goog.require('goog.dom.ViewportSizeMonitor');
</script>
<link rel="stylesheet" href="css/demo.css">
<style>
html, body {
margin: 0;
border: 0;
padding: 10px;
overflow: hidden;
}
div#demo {
position: relative;
top: 0;
left: 0;
margin: 0;
border: 0;
padding: 0;
}
span#current_size {
font: bold 9pt Arial, Helvetica, sans-serif;
color: #333;
white-space: nowrap;
}
</style>
</head>
<body>
<h1>goog.dom.ViewportSizeMonitor</h1>
<div id="demo">
Current Size: <span id="current_size">Loading...</span>
</div>
<script>
// Takes a goog.math.Size object containing the viewport size, and updates
// the UI accordingly.
function updateUi(size) {
goog.style.setSize(goog.dom.getElement('demo'), size);
goog.dom.setTextContent(goog.dom.getElement('current_size'),
size.toString());
}
// Initialize the layout.
updateUi(goog.dom.getViewportSize());
// Start listening for viewport size changes.
var vsm = new goog.dom.ViewportSizeMonitor();
goog.events.listen(vsm, goog.events.EventType.RESIZE, function(e) {
updateUi(vsm.getSize());
});
</script>
</body>
</html>
|