Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

anim-curve-debug.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('anim-curve', function(Y) {
  9. /**
  10. * Adds support for the <code>curve</code> property for the <code>to</code>
  11. * attribute. A curve is zero or more control points and an end point.
  12. * @module anim
  13. * @submodule anim-curve
  14. */
  15. Y.Anim.behaviors.curve = {
  16. set: function(anim, att, from, to, elapsed, duration, fn) {
  17. from = from.slice.call(from);
  18. to = to.slice.call(to);
  19. var t = fn(elapsed, 0, 100, duration) / 100;
  20. to.unshift(from);
  21. anim._node.setXY(Y.Anim.getBezier(to, t));
  22. },
  23. get: function(anim, att) {
  24. return anim._node.getXY();
  25. }
  26. };
  27. /**
  28. * Get the current position of the animated element based on t.
  29. * Each point is an array of "x" and "y" values (0 = x, 1 = y)
  30. * At least 2 points are required (start and end).
  31. * First point is start. Last point is end.
  32. * Additional control points are optional.
  33. * @for Anim
  34. * @method getBezier
  35. * @static
  36. * @param {Array} points An array containing Bezier points
  37. * @param {Number} t A number between 0 and 1 which is the basis for determining current position
  38. * @return {Array} An array containing int x and y member data
  39. */
  40. Y.Anim.getBezier = function(points, t) {
  41. var n = points.length;
  42. var tmp = [];
  43. for (var i = 0; i < n; ++i){
  44. tmp[i] = [points[i][0], points[i][1]]; // save input
  45. }
  46. for (var j = 1; j < n; ++j) {
  47. for (i = 0; i < n - j; ++i) {
  48. tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
  49. tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
  50. }
  51. }
  52. return [ tmp[0][0], tmp[0][1] ];
  53. };
  54. }, '3.4.0' ,{requires:['anim-xy']});