控件支持动画效果

DSL中的部分控件是可以添加动画的,如:容器类、按钮、标签等。

支持控件动画的type:

  • “translate”//移动
  • “scale”//伸缩
  • “rotate”//旋转
  • “alpha”//渐隐

每个type类型支持以下style:

  • “accelerate”//加速
  • “decelerate”//减速
  • “bounce”//反弹

通过type与style结合使用,达到移动加速、移动减速、移动反弹、伸缩加速、伸缩减速、伸缩反弹、旋转加速、旋转减速、旋转反弹、渐隐加速、渐隐减速、渐隐反弹的效果,对同一个控件动画效果可以叠加使用如达到渐隐与移动加速的效果。

示例

  1. <div id="viewPage0">
  2. <input id="button0" value="移动加速" onclick="translate_acc()" type="button"/>
  3. <input id="button1" value="移动减速" onclick="translate_dece()" type="button"/>
  4. <input id="button2" value="移动反弹" onclick="translate_bounce()" type="button"/>
  5. <input id="button3" value="渐隐伸缩减速" onclick="scale_alpha()" type="button"/>
  6. <input id="button4" value="渐隐移动旋转" onclick="translate_bounce()" type="button"/>
  7. </div>
  1. functionstart(sender, args) {
  2. //移动加速效果
  3. varanimations0 = {
  4. type : "translate", //移动类型,画面转换位置移动动画效果
  5. duration : 3000, //毫秒,默认1000
  6. fromX : 300, //int类型,leftMargin的大小
  7. toX : 10, //int类型,leftMargin的大小
  8. fromY : 500, //int类型,topMargin的大小
  9. toY : 50, //int类型,topMargin的大小
  10. repeatCount : "3", //int类型,重复的次数
  11. style : "accelerate"//加速
  12. };
  13. $id("button0").animate(animations0);
  14. //移动减速效果
  15. varanimations1 = {
  16. type : "translate", //移动类型,画面转换位置移动动画效果
  17. duration : 3000, //毫秒,默认1000
  18. fromX : 300, //int类型,leftMargin的大小
  19. toX : 10, //int类型,leftMargin的大小
  20. fromY : 500, //int类型,topMargin的大小
  21. toY : 50, //int类型,topMargin的大小
  22. repeatCount : "3", //int类型,重复的次数
  23. style : "decelerate"//加速
  24. };
  25. $id("button1").animate(animations1);
  26. //移动反弹效果
  27. varanimations2 = {
  28. type : "translate", //移动类型,画面转换位置移动动画效果
  29. duration : 3000, //毫秒,默认1000
  30. fromX : 300, //int类型,leftMargin的大小
  31. toX : 10, //int类型,leftMargin的大小
  32. fromY : 500, //int类型,topMargin的大小
  33. toY : 50, //int类型,topMargin的大小
  34. repeatCount : "3", //int类型,重复的次数
  35. style : "bounce"//反弹
  36. };
  37. $id("button2").animate(animations2);
  38. //渐隐+伸缩减速效果
  39. varanimations3 = [{
  40. type : "alpha", //渐隐类型
  41. duration : 3000, //毫秒,默认1000
  42. fromAlpha : 0.3, //float类型,0-1,0为全透,1为完全不透
  43. toAlpha : 1, //float类型,0-1,0为全透,1为完全不透
  44. repeatCount : 2//int类型,重复的次数
  45. }, {
  46. type : "scale", //渐变尺寸伸缩动画效果
  47. duration : 3000,
  48. fromWidth : "fill",
  49. toWidth : "fill",
  50. fromHeight : "0",
  51. toHeight : "68",
  52. pivotX : "0",
  53. pivotY : "0",
  54. style : "decelerate"//减速
  55. }];
  56. $id("button3").animate(animations3);
  57. //渐隐+移动旋转效果
  58. varanimations4 = [{
  59. type : "translate", //移动类型
  60. duration : 3000, //毫秒,默认1000
  61. fromX : 100, //int类型,leftMargin的大小
  62. toX : 280, //int类型,leftMargin的大小
  63. fromY : 10, //int类型,topMargin的大小
  64. toY : 500, //int类型,topMargin的大小
  65. repeatCount : "3", //int类型,重复的次数
  66. style : "bounce"
  67. }, {
  68. type : "alpha", //渐隐类型
  69. duration : 3000, //毫秒,默认1000
  70. fromAlpha : 0.3, //float类型,0-1,0为全透,1为完全不透
  71. toAlpha : 1, //float类型,0-1,0为全透,1为完全不透
  72. repeatCount : 0//int类型,重复的次数
  73. }];
  74. $id("button4").animate(animations4);
  75. }
文档更新时间: 2018-05-08 13:42