| 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.fx.dom</title> |
| 11 |
<script src="../base.js"></script> |
| 12 |
<script> |
| 13 |
goog.require('goog.events'); |
| 14 |
goog.require('goog.fx'); |
| 15 |
goog.require('goog.fx.dom'); |
| 16 |
</script> |
| 17 |
<link rel="stylesheet" href="css/demo.css"> |
| 18 |
<style> |
| 19 |
#test1 { |
| 20 |
position: absolute; |
| 21 |
left: 150px; |
| 22 |
top: 100px; |
| 23 |
width: 20px; |
| 24 |
height: 20px; |
| 25 |
background-color: rgb(0,0,0); |
| 26 |
} |
| 27 |
|
| 28 |
button { |
| 29 |
font: normal 10px arial; |
| 30 |
width: 125px; |
| 31 |
} |
| 32 |
</style> |
| 33 |
</head> |
| 34 |
<body> |
| 35 |
<h1>goog.fx.dom</h1> |
| 36 |
<p><strong>Demonstrations of the goog.fx.dom library</strong></p> |
| 37 |
|
| 38 |
<p> |
| 39 |
<button id="but0" onclick="slide(0, 0);">Slide To 0x0</button><br> |
| 40 |
<button id="but1" onclick="slide(400, 40);">Slide To 400x40</button><br> |
| 41 |
<button id="but2" onclick="slide(300, 200);">Slide To 300x200</button><br> |
| 42 |
<button id="but3" onclick="slide(600, 100);">Slide To 600x100</button> |
| 43 |
</p> |
| 44 |
|
| 45 |
<p> |
| 46 |
<button id="but4" onclick="resize(50, 50);">Resize To 50x50</button><br> |
| 47 |
<button id="but5" onclick="resize(250, 50);">Resize To 250x50</button><br> |
| 48 |
<button id="but6" onclick="resize(5, 5);">Resize To 5x5</button><br> |
| 49 |
<button id="but7" onclick="resize(250, 250);">Resize To 250x250</button><br> |
| 50 |
<button id="but8" onclick="resize(1250, 1250);">Resize To 1250x1250</button> |
| 51 |
</p> |
| 52 |
|
| 53 |
<p> |
| 54 |
<button id="but9" onclick="fadeout();">Fade Out</button><br> |
| 55 |
<button id="but10" onclick="fadein();">Fade In</button> |
| 56 |
</p> |
| 57 |
|
| 58 |
<p> |
| 59 |
<button id="but11" onclick="color(200, 0, 0);">Transform to red</button><br> |
| 60 |
<button id="but12" onclick="color(180, 180, 180);">Transform to grey</button><br> |
| 61 |
<button id="but13" onclick="color(0, 0, 0);">Transform to black</button><br> |
| 62 |
<button id="but14" onclick="color(100, 100, 255);">Transform to blue</button> |
| 63 |
</p> |
| 64 |
|
| 65 |
<p> |
| 66 |
<button id="but15" onclick="toggleRequestAnimationFrame();"></button> |
| 67 |
<p> |
| 68 |
|
| 69 |
|
| 70 |
<div id="test1"><!-- This comment is an IE6 hack to fix height:20px --></div> |
| 71 |
|
| 72 |
<script> |
| 73 |
var col = [0, 0, 0]; |
| 74 |
var duration = 1000; |
| 75 |
|
| 76 |
var el = document.getElementById('test1'); |
| 77 |
|
| 78 |
/** |
| 79 |
* Enables all buttons then disposes of the animation. |
| 80 |
* @param {!goog.events.Event} e goog.fx.Transition.EventType.END event with |
| 81 |
* the goog.fx.Animation object in its target. |
| 82 |
*/ |
| 83 |
function enableButtons(e) { |
| 84 |
for (var i = 0; i <= 15; i++) { |
| 85 |
document.getElementById('but' + i).disabled = false; |
| 86 |
} |
| 87 |
e.target.dispose(); |
| 88 |
} |
| 89 |
|
| 90 |
function disableButtons() { |
| 91 |
for (var i = 0; i <= 15; i++) { |
| 92 |
document.getElementById('but' + i).disabled = true; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
function slide(a, b) { |
| 97 |
var x = el.offsetLeft; |
| 98 |
var y = el.offsetTop; |
| 99 |
var anim = new goog.fx.dom.Slide(el, [x, y], [a, b], duration, |
| 100 |
goog.fx.easing.easeOut); |
| 101 |
goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN, |
| 102 |
disableButtons); |
| 103 |
goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons); |
| 104 |
anim.play(); |
| 105 |
} |
| 106 |
|
| 107 |
function resize(a, b) { |
| 108 |
var w = el.offsetWidth; |
| 109 |
var h = el.offsetHeight; |
| 110 |
var anim = new goog.fx.dom.Resize(el, [w, h], [a, b], duration, |
| 111 |
goog.fx.easing.easeOut); |
| 112 |
goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN, |
| 113 |
disableButtons); |
| 114 |
goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons); |
| 115 |
anim.play(); |
| 116 |
} |
| 117 |
|
| 118 |
function fadeout() { |
| 119 |
var anim = new goog.fx.dom.FadeOutAndHide(el, duration); |
| 120 |
goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN, |
| 121 |
disableButtons); |
| 122 |
goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons); |
| 123 |
anim.play(); |
| 124 |
} |
| 125 |
|
| 126 |
function fadein() { |
| 127 |
var anim = new goog.fx.dom.FadeInAndShow(el, duration); |
| 128 |
goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN, |
| 129 |
disableButtons); |
| 130 |
goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons); |
| 131 |
anim.play(); |
| 132 |
} |
| 133 |
|
| 134 |
function color(r, g, b) { |
| 135 |
var anim = new goog.fx.dom.BgColorTransform(el, col, [r, g, b], duration); |
| 136 |
goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN, |
| 137 |
disableButtons); |
| 138 |
goog.events.listen(anim, goog.fx.Transition.EventType.END, function(e) { |
| 139 |
col = [e.x, e.y, e.z]; |
| 140 |
enableButtons(); |
| 141 |
}); |
| 142 |
anim.play(); |
| 143 |
} |
| 144 |
|
| 145 |
function toggleRequestAnimationFrame() { |
| 146 |
rafEnabled = !rafEnabled; |
| 147 |
goog.fx.Animation.setAnimationWindow(rafEnabled ? window : null); |
| 148 |
updateRafButton(); |
| 149 |
} |
| 150 |
|
| 151 |
function updateRafButton() { |
| 152 |
goog.dom.setTextContent(goog.dom.getElement('but15'), |
| 153 |
rafEnabled ? |
| 154 |
'Disable timing control API' : 'Enable timing control API'); |
| 155 |
} |
| 156 |
|
| 157 |
goog.fx.Animation.setAnimationWindow(window); |
| 158 |
var rafEnabled = goog.fx.Animation.animationWindow_; |
| 159 |
updateRafButton(); |
| 160 |
</script> |
| 161 |
</body> |
| 162 |
</html> |