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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
|
// Copyright 2005 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Predefined DHTML animations such as slide, resize and fade.
*
* @see ../demos/effects.html
*/
goog.provide('goog.fx.dom');
goog.provide('goog.fx.dom.BgColorTransform');
goog.provide('goog.fx.dom.ColorTransform');
goog.provide('goog.fx.dom.Fade');
goog.provide('goog.fx.dom.FadeIn');
goog.provide('goog.fx.dom.FadeInAndShow');
goog.provide('goog.fx.dom.FadeOut');
goog.provide('goog.fx.dom.FadeOutAndHide');
goog.provide('goog.fx.dom.PredefinedEffect');
goog.provide('goog.fx.dom.Resize');
goog.provide('goog.fx.dom.ResizeHeight');
goog.provide('goog.fx.dom.ResizeWidth');
goog.provide('goog.fx.dom.Scroll');
goog.provide('goog.fx.dom.Slide');
goog.provide('goog.fx.dom.SlideFrom');
goog.provide('goog.fx.dom.Swipe');
goog.require('goog.color');
goog.require('goog.events');
goog.require('goog.fx.Animation');
goog.require('goog.fx.Transition');
goog.require('goog.style');
goog.require('goog.style.bidi');
goog.forwardDeclare('goog.events.EventHandler');
/**
* Abstract class that provides reusable functionality for predefined animations
* that manipulate a single DOM element
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start Array for start coordinates.
* @param {Array<number>} end Array for end coordinates.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.Animation}
* @constructor
* @struct
*/
goog.fx.dom.PredefinedEffect = function(element, start, end, time, opt_acc) {
goog.fx.Animation.call(this, start, end, time, opt_acc);
/**
* DOM Node that will be used in the animation
* @type {Element}
*/
this.element = element;
/**
* Whether the element is rendered right-to-left. We cache this here for
* efficiency.
* @private {boolean|undefined}
*/
this.rightToLeft_;
};
goog.inherits(goog.fx.dom.PredefinedEffect, goog.fx.Animation);
/**
* Called to update the style of the element.
* @protected
*/
goog.fx.dom.PredefinedEffect.prototype.updateStyle = goog.nullFunction;
/**
* Whether the DOM element being manipulated is rendered right-to-left.
* @return {boolean} True if the DOM element is rendered right-to-left, false
* otherwise.
*/
goog.fx.dom.PredefinedEffect.prototype.isRightToLeft = function() {
if (!goog.isDef(this.rightToLeft_)) {
this.rightToLeft_ = goog.style.isRightToLeft(this.element);
}
return this.rightToLeft_;
};
/** @override */
goog.fx.dom.PredefinedEffect.prototype.onAnimate = function() {
this.updateStyle();
goog.fx.dom.PredefinedEffect.superClass_.onAnimate.call(this);
};
/** @override */
goog.fx.dom.PredefinedEffect.prototype.onEnd = function() {
this.updateStyle();
goog.fx.dom.PredefinedEffect.superClass_.onEnd.call(this);
};
/** @override */
goog.fx.dom.PredefinedEffect.prototype.onBegin = function() {
this.updateStyle();
goog.fx.dom.PredefinedEffect.superClass_.onBegin.call(this);
};
/**
* Creates an animation object that will slide an element from A to B. (This
* in effect automatically sets up the onanimate event for an Animation object)
*
* Start and End should be 2 dimensional arrays
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start 2D array for start coordinates (X, Y).
* @param {Array<number>} end 2D array for end coordinates (X, Y).
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.Slide = function(element, start, end, time, opt_acc) {
if (start.length != 2 || end.length != 2) {
throw new Error('Start and end points must be 2D');
}
goog.fx.dom.PredefinedEffect.apply(this, arguments);
};
goog.inherits(goog.fx.dom.Slide, goog.fx.dom.PredefinedEffect);
/** @override */
goog.fx.dom.Slide.prototype.updateStyle = function() {
var pos = (this.isRightPositioningForRtlEnabled() && this.isRightToLeft()) ?
'right' :
'left';
this.element.style[pos] = Math.round(this.coords[0]) + 'px';
this.element.style.top = Math.round(this.coords[1]) + 'px';
};
/**
* Slides an element from its current position.
*
* @param {Element} element DOM node to be used in the animation.
* @param {Array<number>} end 2D array for end coordinates (X, Y).
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.Slide}
* @constructor
* @struct
*/
goog.fx.dom.SlideFrom = function(element, end, time, opt_acc) {
/** @type {?Array<number>} */
this.startPoint;
var offsetLeft = this.isRightPositioningForRtlEnabled() ?
goog.style.bidi.getOffsetStart(element) :
/** @type {!HTMLElement} */ (element).offsetLeft;
var start = [offsetLeft, /** @type {!HTMLElement} */ (element).offsetTop];
goog.fx.dom.Slide.call(this, element, start, end, time, opt_acc);
};
goog.inherits(goog.fx.dom.SlideFrom, goog.fx.dom.Slide);
/** @override */
goog.fx.dom.SlideFrom.prototype.onBegin = function() {
var offsetLeft = this.isRightPositioningForRtlEnabled() ?
goog.style.bidi.getOffsetStart(this.element) :
this.element.offsetLeft;
this.startPoint = [
offsetLeft,
/** @type {!HTMLElement} */ (this.element).offsetTop
];
goog.fx.dom.SlideFrom.superClass_.onBegin.call(this);
};
/**
* Creates an animation object that will slide an element into its final size.
* Requires that the element is absolutely positioned.
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start 2D array for start size (W, H).
* @param {Array<number>} end 2D array for end size (W, H).
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.Swipe = function(element, start, end, time, opt_acc) {
if (start.length != 2 || end.length != 2) {
throw new Error('Start and end points must be 2D');
}
goog.fx.dom.PredefinedEffect.apply(this, arguments);
/**
* Maximum width for element.
* @type {number}
* @private
*/
this.maxWidth_ = Math.max(this.endPoint[0], this.startPoint[0]);
/**
* Maximum height for element.
* @type {number}
* @private
*/
this.maxHeight_ = Math.max(this.endPoint[1], this.startPoint[1]);
};
goog.inherits(goog.fx.dom.Swipe, goog.fx.dom.PredefinedEffect);
/**
* Animation event handler that will resize an element by setting its width,
* height and clipping.
* @protected
* @override
*/
goog.fx.dom.Swipe.prototype.updateStyle = function() {
var x = this.coords[0];
var y = this.coords[1];
this.clip_(Math.round(x), Math.round(y), this.maxWidth_, this.maxHeight_);
this.element.style.width = Math.round(x) + 'px';
var marginX =
(this.isRightPositioningForRtlEnabled() && this.isRightToLeft()) ?
'marginRight' :
'marginLeft';
this.element.style[marginX] = Math.round(x) - this.maxWidth_ + 'px';
this.element.style.marginTop = Math.round(y) - this.maxHeight_ + 'px';
};
/**
* Helper function for setting element clipping.
* @param {number} x Current element width.
* @param {number} y Current element height.
* @param {number} w Maximum element width.
* @param {number} h Maximum element height.
* @private
*/
goog.fx.dom.Swipe.prototype.clip_ = function(x, y, w, h) {
this.element.style.clip =
'rect(' + (h - y) + 'px ' + w + 'px ' + h + 'px ' + (w - x) + 'px)';
};
/**
* Creates an animation object that will scroll an element from A to B.
*
* Start and End should be 2 dimensional arrays
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start 2D array for start scroll left and top.
* @param {Array<number>} end 2D array for end scroll left and top.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.Scroll = function(element, start, end, time, opt_acc) {
if (start.length != 2 || end.length != 2) {
throw new Error('Start and end points must be 2D');
}
goog.fx.dom.PredefinedEffect.apply(this, arguments);
};
goog.inherits(goog.fx.dom.Scroll, goog.fx.dom.PredefinedEffect);
/**
* Animation event handler that will set the scroll position of an element.
* @protected
* @override
*/
goog.fx.dom.Scroll.prototype.updateStyle = function() {
if (this.isRightPositioningForRtlEnabled()) {
goog.style.bidi.setScrollOffset(this.element, Math.round(this.coords[0]));
} else {
this.element.scrollLeft = Math.round(this.coords[0]);
}
this.element.scrollTop = Math.round(this.coords[1]);
};
/**
* Creates an animation object that will resize an element between two widths
* and heights.
*
* Start and End should be 2 dimensional arrays
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start 2D array for start width and height.
* @param {Array<number>} end 2D array for end width and height.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.Resize = function(element, start, end, time, opt_acc) {
if (start.length != 2 || end.length != 2) {
throw new Error('Start and end points must be 2D');
}
goog.fx.dom.PredefinedEffect.apply(this, arguments);
};
goog.inherits(goog.fx.dom.Resize, goog.fx.dom.PredefinedEffect);
/**
* Animation event handler that will resize an element by setting its width and
* height.
* @protected
* @override
*/
goog.fx.dom.Resize.prototype.updateStyle = function() {
this.element.style.width = Math.round(this.coords[0]) + 'px';
this.element.style.height = Math.round(this.coords[1]) + 'px';
};
/**
* Creates an animation object that will resize an element between two widths
*
* Start and End should be numbers
*
* @param {Element} element Dom Node to be used in the animation.
* @param {number} start Start width.
* @param {number} end End width.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.ResizeWidth = function(element, start, end, time, opt_acc) {
goog.fx.dom.PredefinedEffect.call(
this, element, [start], [end], time, opt_acc);
};
goog.inherits(goog.fx.dom.ResizeWidth, goog.fx.dom.PredefinedEffect);
/**
* Animation event handler that will resize an element by setting its width.
* @protected
* @override
*/
goog.fx.dom.ResizeWidth.prototype.updateStyle = function() {
this.element.style.width = Math.round(this.coords[0]) + 'px';
};
/**
* Creates an animation object that will resize an element between two heights
*
* Start and End should be numbers
*
* @param {Element} element Dom Node to be used in the animation.
* @param {number} start Start height.
* @param {number} end End height.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.ResizeHeight = function(element, start, end, time, opt_acc) {
goog.fx.dom.PredefinedEffect.call(
this, element, [start], [end], time, opt_acc);
};
goog.inherits(goog.fx.dom.ResizeHeight, goog.fx.dom.PredefinedEffect);
/**
* Animation event handler that will resize an element by setting its height.
* @protected
* @override
*/
goog.fx.dom.ResizeHeight.prototype.updateStyle = function() {
this.element.style.height = Math.round(this.coords[0]) + 'px';
};
/**
* Creates an animation object that fades the opacity of an element between two
* limits.
*
* Start and End should be floats between 0 and 1
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>|number} start 1D Array or Number with start opacity.
* @param {Array<number>|number} end 1D Array or Number for end opacity.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.Fade = function(element, start, end, time, opt_acc) {
if (goog.isNumber(start)) start = [start];
if (goog.isNumber(end)) end = [end];
goog.fx.dom.Fade.base(
this, 'constructor', element, start, end, time, opt_acc);
if (start.length != 1 || end.length != 1) {
throw new Error('Start and end points must be 1D');
}
/**
* The last opacity we set, or -1 for not set.
* @private {number}
*/
this.lastOpacityUpdate_ = goog.fx.dom.Fade.OPACITY_UNSET_;
};
goog.inherits(goog.fx.dom.Fade, goog.fx.dom.PredefinedEffect);
/**
* The quantization of opacity values to use.
* @private {number}
*/
goog.fx.dom.Fade.TOLERANCE_ = 1.0 / 0x400; // 10-bit color
/**
* Value indicating that the opacity must be set on next update.
* @private {number}
*/
goog.fx.dom.Fade.OPACITY_UNSET_ = -1;
/**
* Animation event handler that will set the opacity of an element.
* @protected
* @override
*/
goog.fx.dom.Fade.prototype.updateStyle = function() {
var opacity = this.coords[0];
var delta = Math.abs(opacity - this.lastOpacityUpdate_);
// In order to keep eager browsers from over-rendering, only update
// on a potentially visible change in opacity.
if (delta >= goog.fx.dom.Fade.TOLERANCE_) {
goog.style.setOpacity(this.element, opacity);
this.lastOpacityUpdate_ = opacity;
}
};
/** @override */
goog.fx.dom.Fade.prototype.onBegin = function() {
this.lastOpacityUpdate_ = goog.fx.dom.Fade.OPACITY_UNSET_;
goog.fx.dom.Fade.base(this, 'onBegin');
};
/** @override */
goog.fx.dom.Fade.prototype.onEnd = function() {
this.lastOpacityUpdate_ = goog.fx.dom.Fade.OPACITY_UNSET_;
goog.fx.dom.Fade.base(this, 'onEnd');
};
/**
* Animation event handler that will show the element.
*/
goog.fx.dom.Fade.prototype.show = function() {
this.element.style.display = '';
};
/**
* Animation event handler that will hide the element
*/
goog.fx.dom.Fade.prototype.hide = function() {
this.element.style.display = 'none';
};
/**
* Fades an element out from full opacity to completely transparent.
*
* @param {Element} element Dom Node to be used in the animation.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.Fade}
* @constructor
* @struct
*/
goog.fx.dom.FadeOut = function(element, time, opt_acc) {
goog.fx.dom.Fade.call(this, element, 1, 0, time, opt_acc);
};
goog.inherits(goog.fx.dom.FadeOut, goog.fx.dom.Fade);
/**
* Fades an element in from completely transparent to fully opacity.
*
* @param {Element} element Dom Node to be used in the animation.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.Fade}
* @constructor
* @struct
*/
goog.fx.dom.FadeIn = function(element, time, opt_acc) {
goog.fx.dom.Fade.call(this, element, 0, 1, time, opt_acc);
};
goog.inherits(goog.fx.dom.FadeIn, goog.fx.dom.Fade);
/**
* Fades an element out from full opacity to completely transparent and then
* sets the display to 'none'
*
* @param {Element} element Dom Node to be used in the animation.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.Fade}
* @constructor
* @struct
*/
goog.fx.dom.FadeOutAndHide = function(element, time, opt_acc) {
goog.fx.dom.Fade.call(this, element, 1, 0, time, opt_acc);
};
goog.inherits(goog.fx.dom.FadeOutAndHide, goog.fx.dom.Fade);
/** @override */
goog.fx.dom.FadeOutAndHide.prototype.onBegin = function() {
this.show();
goog.fx.dom.FadeOutAndHide.superClass_.onBegin.call(this);
};
/** @override */
goog.fx.dom.FadeOutAndHide.prototype.onEnd = function() {
this.hide();
goog.fx.dom.FadeOutAndHide.superClass_.onEnd.call(this);
};
/**
* Sets an element's display to be visible and then fades an element in from
* completely transparent to fully opaque.
*
* @param {Element} element Dom Node to be used in the animation.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.Fade}
* @constructor
* @struct
*/
goog.fx.dom.FadeInAndShow = function(element, time, opt_acc) {
goog.fx.dom.Fade.call(this, element, 0, 1, time, opt_acc);
};
goog.inherits(goog.fx.dom.FadeInAndShow, goog.fx.dom.Fade);
/** @override */
goog.fx.dom.FadeInAndShow.prototype.onBegin = function() {
this.show();
goog.fx.dom.FadeInAndShow.superClass_.onBegin.call(this);
};
/**
* Provides a transformation of an elements background-color.
*
* Start and End should be 3D arrays representing R,G,B
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start 3D Array for RGB of start color.
* @param {Array<number>} end 3D Array for RGB of end color.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @extends {goog.fx.dom.PredefinedEffect}
* @constructor
* @struct
*/
goog.fx.dom.BgColorTransform = function(element, start, end, time, opt_acc) {
if (start.length != 3 || end.length != 3) {
throw new Error('Start and end points must be 3D');
}
goog.fx.dom.PredefinedEffect.apply(this, arguments);
};
goog.inherits(goog.fx.dom.BgColorTransform, goog.fx.dom.PredefinedEffect);
/**
* Animation event handler that will set the background-color of an element
*/
goog.fx.dom.BgColorTransform.prototype.setColor = function() {
var coordsAsInts = [];
for (var i = 0; i < this.coords.length; i++) {
coordsAsInts[i] = Math.round(this.coords[i]);
}
var color = 'rgb(' + coordsAsInts.join(',') + ')';
this.element.style.backgroundColor = color;
};
/** @override */
goog.fx.dom.BgColorTransform.prototype.updateStyle = function() {
this.setColor();
};
/**
* Fade elements background color from start color to the element's current
* background color.
*
* Start should be a 3D array representing R,G,B
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start 3D Array for RGB of start color.
* @param {number} time Length of animation in milliseconds.
* @param {goog.events.EventHandler=} opt_eventHandler Optional event handler
* to use when listening for events.
*/
goog.fx.dom.bgColorFadeIn = function(element, start, time, opt_eventHandler) {
var initialBgColor = element.style.backgroundColor || '';
var computedBgColor = goog.style.getBackgroundColor(element);
var end;
if (computedBgColor && computedBgColor != 'transparent' &&
computedBgColor != 'rgba(0, 0, 0, 0)') {
end = goog.color.hexToRgb(goog.color.parse(computedBgColor).hex);
} else {
end = [255, 255, 255];
}
var anim = new goog.fx.dom.BgColorTransform(element, start, end, time);
function setBgColor() { element.style.backgroundColor = initialBgColor; }
if (opt_eventHandler) {
opt_eventHandler.listen(anim, goog.fx.Transition.EventType.END, setBgColor);
} else {
goog.events.listen(anim, goog.fx.Transition.EventType.END, setBgColor);
}
anim.play();
};
/**
* Provides a transformation of an elements color.
*
* @param {Element} element Dom Node to be used in the animation.
* @param {Array<number>} start 3D Array representing R,G,B.
* @param {Array<number>} end 3D Array representing R,G,B.
* @param {number} time Length of animation in milliseconds.
* @param {Function=} opt_acc Acceleration function, returns 0-1 for inputs 0-1.
* @constructor
* @struct
* @extends {goog.fx.dom.PredefinedEffect}
*/
goog.fx.dom.ColorTransform = function(element, start, end, time, opt_acc) {
if (start.length != 3 || end.length != 3) {
throw new Error('Start and end points must be 3D');
}
goog.fx.dom.PredefinedEffect.apply(this, arguments);
};
goog.inherits(goog.fx.dom.ColorTransform, goog.fx.dom.PredefinedEffect);
/**
* Animation event handler that will set the color of an element.
* @protected
* @override
*/
goog.fx.dom.ColorTransform.prototype.updateStyle = function() {
var coordsAsInts = [];
for (var i = 0; i < this.coords.length; i++) {
coordsAsInts[i] = Math.round(this.coords[i]);
}
var color = 'rgb(' + coordsAsInts.join(',') + ')';
this.element.style.color = color;
};
|