easing.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2006 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Easing functions for animations.
  16. *
  17. * @author arv@google.com (Erik Arvidsson)
  18. */
  19. goog.provide('goog.fx.easing');
  20. /**
  21. * Ease in - Start slow and speed up.
  22. * @param {number} t Input between 0 and 1.
  23. * @return {number} Output between 0 and 1.
  24. */
  25. goog.fx.easing.easeIn = function(t) {
  26. return goog.fx.easing.easeInInternal_(t, 3);
  27. };
  28. /**
  29. * Ease in with specifiable exponent.
  30. * @param {number} t Input between 0 and 1.
  31. * @param {number} exp Ease exponent.
  32. * @return {number} Output between 0 and 1.
  33. * @private
  34. */
  35. goog.fx.easing.easeInInternal_ = function(t, exp) {
  36. return Math.pow(t, exp);
  37. };
  38. /**
  39. * Ease out - Start fastest and slows to a stop.
  40. * @param {number} t Input between 0 and 1.
  41. * @return {number} Output between 0 and 1.
  42. */
  43. goog.fx.easing.easeOut = function(t) {
  44. return goog.fx.easing.easeOutInternal_(t, 3);
  45. };
  46. /**
  47. * Ease out with specifiable exponent.
  48. * @param {number} t Input between 0 and 1.
  49. * @param {number} exp Ease exponent.
  50. * @return {number} Output between 0 and 1.
  51. * @private
  52. */
  53. goog.fx.easing.easeOutInternal_ = function(t, exp) {
  54. return 1 - goog.fx.easing.easeInInternal_(1 - t, exp);
  55. };
  56. /**
  57. * Ease out long - Start fastest and slows to a stop with a long ease.
  58. * @param {number} t Input between 0 and 1.
  59. * @return {number} Output between 0 and 1.
  60. */
  61. goog.fx.easing.easeOutLong = function(t) {
  62. return goog.fx.easing.easeOutInternal_(t, 4);
  63. };
  64. /**
  65. * Ease in and out - Start slow, speed up, then slow down.
  66. * @param {number} t Input between 0 and 1.
  67. * @return {number} Output between 0 and 1.
  68. */
  69. goog.fx.easing.inAndOut = function(t) {
  70. return 3 * t * t - 2 * t * t * t;
  71. };