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