]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/src/fx/easing/BoundMomentum.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / src / fx / easing / BoundMomentum.js
CommitLineData
6527f429
DM
1/**\r
2 * @private\r
3 *\r
4 * This easing is typically used for {@link Ext.scroll.Scroller}. It's a combination of\r
5 * {@link Ext.fx.easing.Momentum} and {@link Ext.fx.easing.Bounce}, which emulates deceleration when the animated element\r
6 * is still within its boundary, then bouncing back (snapping) when it's out-of-bound.\r
7 */\r
8\r
9Ext.define('Ext.fx.easing.BoundMomentum', {\r
10 extend: 'Ext.fx.easing.Abstract',\r
11\r
12 requires: [\r
13 'Ext.fx.easing.Momentum',\r
14 'Ext.fx.easing.Bounce'\r
15 ],\r
16\r
17 config: {\r
18 /**\r
19 * @cfg {Object} momentum\r
20 * A valid config object for {@link Ext.fx.easing.Momentum}\r
21 * @accessor\r
22 */\r
23 momentum: null,\r
24\r
25 /**\r
26 * @cfg {Object} bounce\r
27 * A valid config object for {@link Ext.fx.easing.Bounce}\r
28 * @accessor\r
29 */\r
30 bounce: null,\r
31\r
32 minMomentumValue: 0,\r
33\r
34 maxMomentumValue: 0,\r
35\r
36 /**\r
37 * @cfg {Number} minVelocity\r
38 * The minimum velocity to end this easing\r
39 * @accessor\r
40 */\r
41 minVelocity: 0.01,\r
42\r
43 /**\r
44 * @cfg {Number} startVelocity\r
45 * The start velocity\r
46 * @accessor\r
47 */\r
48 startVelocity: 0\r
49 },\r
50\r
51 applyMomentum: function(config, currentEasing) {\r
52 return Ext.factory(config, Ext.fx.easing.Momentum, currentEasing);\r
53 },\r
54\r
55 applyBounce: function(config, currentEasing) {\r
56 return Ext.factory(config, Ext.fx.easing.Bounce, currentEasing);\r
57 },\r
58\r
59 updateStartTime: function(startTime) {\r
60 this.getMomentum().setStartTime(startTime);\r
61\r
62 this.callParent(arguments);\r
63 },\r
64\r
65 updateStartVelocity: function(startVelocity) {\r
66 this.getMomentum().setStartVelocity(startVelocity);\r
67 },\r
68\r
69 updateStartValue: function(startValue) {\r
70 this.getMomentum().setStartValue(startValue);\r
71 },\r
72\r
73 reset: function() {\r
74 this.lastValue = null;\r
75\r
76 this.isBouncingBack = false;\r
77\r
78 this.isOutOfBound = false;\r
79\r
80 return this.callParent(arguments);\r
81 },\r
82\r
83 getValue: function() {\r
84 var momentum = this.getMomentum(),\r
85 bounce = this.getBounce(),\r
86 startVelocity = momentum.getStartVelocity(),\r
87 direction = startVelocity > 0 ? 1 : -1,\r
88 minValue = this.getMinMomentumValue(),\r
89 maxValue = this.getMaxMomentumValue(),\r
90 boundedValue = (direction == 1) ? maxValue : minValue,\r
91 lastValue = this.lastValue,\r
92 value, velocity;\r
93\r
94 if (startVelocity === 0) {\r
95 return this.getStartValue();\r
96 }\r
97\r
98 if (!this.isOutOfBound) {\r
99 value = momentum.getValue();\r
100 velocity = momentum.getVelocity();\r
101\r
102 if (Math.abs(velocity) < this.getMinVelocity()) {\r
103 this.isEnded = true;\r
104 }\r
105\r
106 if (value >= minValue && value <= maxValue) {\r
107 return value;\r
108 }\r
109\r
110 this.isOutOfBound = true;\r
111\r
112 bounce.setStartTime(Ext.Date.now())\r
113 .setStartVelocity(velocity)\r
114 .setStartValue(boundedValue);\r
115 }\r
116\r
117 value = bounce.getValue();\r
118\r
119 if (!this.isEnded) {\r
120 if (!this.isBouncingBack) {\r
121 if (lastValue !== null) {\r
122 if ((direction == 1 && value < lastValue) || (direction == -1 && value > lastValue)) {\r
123 this.isBouncingBack = true;\r
124 }\r
125 }\r
126 }\r
127 else {\r
128 if (Math.round(value) == boundedValue) {\r
129 this.isEnded = true;\r
130 }\r
131 }\r
132 }\r
133\r
134 this.lastValue = value;\r
135\r
136 return value;\r
137 }\r
138});\r