js-components-common-methods.md 29.9 KB
Newer Older
Z
zengyawen 已提交
1 2 3 4
# 通用方法<a name="ZH-CN_TOPIC_0000001127284884"></a>

当组件通过id属性标识后,可以使用该id获取组件对象并调用相关组件方法。

Z
zengyawen 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17
## animate<a name="section16276192233016"></a>

animate\( keyframes: Keyframes, options: Options\):void

-   参数

    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="19.18%" id="mcps1.1.5.1.1"><p>参数名</p>
    </th>
    <th class="cellrowborder" valign="top" width="17.119999999999997%" id="mcps1.1.5.1.2"><p>参数类型</p>
    </th>
    <th class="cellrowborder" valign="top" width="7.5200000000000005%" id="mcps1.1.5.1.3"><p>必填</p>
    </th>
    <th class="cellrowborder" valign="top" width="56.18%" id="mcps1.1.5.1.4"><p>描述</p>
Z
zengyawen 已提交
18 19 20
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
21 22 23 24 25
    <tbody><tr><td class="cellrowborder" valign="top" width="19.18%" headers="mcps1.1.5.1.1 "><p>keyframes</p>
    </td>
    <td class="cellrowborder" valign="top" width="17.119999999999997%" headers="mcps1.1.5.1.2 "><p><a href="#table13611943164319">keyframes</a></p>
    </td>
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p>是</p>
Z
zengyawen 已提交
26
    </td>
Z
zengyawen 已提交
27
    <td class="cellrowborder" valign="top" width="56.18%" headers="mcps1.1.5.1.4 "><p>设置动画样式</p>
Z
zengyawen 已提交
28
    </td>
Z
zengyawen 已提交
29 30 31 32 33 34 35 36
    </tr>
    <tr><td class="cellrowborder" valign="top" width="19.18%" headers="mcps1.1.5.1.1 "><p>options</p>
    </td>
    <td class="cellrowborder" valign="top" width="17.119999999999997%" headers="mcps1.1.5.1.2 "><p><a href="js-components-common-methods.md#table1519818133494">Options</a></p>
    </td>
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p>是</p>
    </td>
    <td class="cellrowborder" valign="top" width="56.18%" headers="mcps1.1.5.1.4 "><p>用于设置动画属性的对象列表。options请见<a href="#table703167514">Options说明</a></p>
Z
zengyawen 已提交
37 38
    </td>
    </tr>
Z
zengyawen 已提交
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
    </tbody>
    </table>

    **表 1**  keyframes

    <a name="table13611943164319"></a>
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="30.503050305030506%" id="mcps1.2.4.1.1"><p>属性</p>
    </th>
    <th class="cellrowborder" valign="top" width="26.642664266426646%" id="mcps1.2.4.1.2"><p>类型</p>
    </th>
    <th class="cellrowborder" valign="top" width="42.85428542854285%" id="mcps1.2.4.1.3"><p>说明</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="30.503050305030506%" headers="mcps1.2.4.1.1 "><p>frames</p>
    </td>
    <td class="cellrowborder" valign="top" width="26.642664266426646%" headers="mcps1.2.4.1.2 "><p>Array&lt;Style&gt;</p>
    </td>
    <td class="cellrowborder" valign="top" width="42.85428542854285%" headers="mcps1.2.4.1.3 "><p>用于设置动画样式的对象列表。Style类型说明请见<a href="#table15168543143">Style类型说明</a></p>
    </td>
    </tr>
    </tbody>
    </table>

    **表 2**  Style类型说明

    <a name="table15168543143"></a>
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="22.91%" id="mcps1.2.5.1.1"><p>参数</p>
    </th>
    <th class="cellrowborder" valign="top" width="10.67%" id="mcps1.2.5.1.2"><p>类型</p>
    </th>
    <th class="cellrowborder" valign="top" width="24.52%" id="mcps1.2.5.1.3"><p>默认值</p>
    </th>
    <th class="cellrowborder" valign="top" width="41.9%" id="mcps1.2.5.1.4"><p>说明</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>width</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><p>动画执行过程中设置到组件上的宽度值。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>height</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><p>动画执行过程中设置到组件上的高度值。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>backgroundColor</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p>&lt;color&gt;</p>
    </td>
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>none</p>
    </td>
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><p>动画执行过程中设置到组件上的背景颜色。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>opacity</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>1</p>
    </td>
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><p>设置到组件上的透明度(介于0到1之间)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>backgroundPosition</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p>string</p>
    </td>
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><p>格式为"x y",单位为百分号或者px。</p>
    <p>第一个值是水平位置,第二个值是垂直位置。</p>
    <p>如果仅规定了一个值,另一个值为 50%。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>transformOrigin</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p>string</p>
Z
zengyawen 已提交
126
    </td>
Z
zengyawen 已提交
127
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>'center center'</p>
Z
zengyawen 已提交
128
    </td>
Z
zengyawen 已提交
129 130 131
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><p>变换对象的中心点。</p>
    <p>第一个参数表示x轴的值,可以设置为left、center、right、长度值或百分比值。</p>
    <p>第二个参数表示y轴的值,可以设置为top、center、bottom、长度值或百分比值。</p>
Z
zengyawen 已提交
132 133
    </td>
    </tr>
Z
zengyawen 已提交
134
    <tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>transform</p>
Z
zengyawen 已提交
135
    </td>
Z
zengyawen 已提交
136
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p><a href="js-components-common-animation.md#table28802443315">Transform</a></p>
Z
zengyawen 已提交
137
    </td>
Z
zengyawen 已提交
138 139 140
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><p>设置到变换对象上的类型。</p>
Z
zengyawen 已提交
141 142
    </td>
    </tr>
Z
zengyawen 已提交
143 144 145
    <tr><td class="cellrowborder" valign="top" width="22.91%" headers="mcps1.2.5.1.1 "><p>offset</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.2.5.1.2 "><p>number</p>
Z
zengyawen 已提交
146
    </td>
Z
zengyawen 已提交
147
    <td class="cellrowborder" valign="top" width="24.52%" headers="mcps1.2.5.1.3 "><p>-</p>
Z
zengyawen 已提交
148
    </td>
Z
zengyawen 已提交
149
    <td class="cellrowborder" valign="top" width="41.9%" headers="mcps1.2.5.1.4 "><ul><li>offset值(如果提供)必须在0.0到1.0(含)之间,并以升序排列。</li><li>若只有两帧,可以不填offset。</li><li>若超过两帧,offset必填。</li></ul>
Z
zengyawen 已提交
150 151 152 153 154
    </td>
    </tr>
    </tbody>
    </table>

Z
zengyawen 已提交
155
    **表 3**  Options说明
Z
zengyawen 已提交
156

Z
zengyawen 已提交
157 158
    <a name="table703167514"></a>
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="18.89%" id="mcps1.2.5.1.1"><p>参数</p>
Z
zengyawen 已提交
159
    </th>
Z
zengyawen 已提交
160
    <th class="cellrowborder" valign="top" width="27.560000000000002%" id="mcps1.2.5.1.2"><p>类型</p>
Z
zengyawen 已提交
161
    </th>
Z
zengyawen 已提交
162 163 164
    <th class="cellrowborder" valign="top" width="18.22%" id="mcps1.2.5.1.3"><p>默认值</p>
    </th>
    <th class="cellrowborder" valign="top" width="35.33%" id="mcps1.2.5.1.4"><p>说明</p>
Z
zengyawen 已提交
165 166 167
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
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
    <tbody><tr><td class="cellrowborder" valign="top" width="18.89%" headers="mcps1.2.5.1.1 "><p>duration</p>
    </td>
    <td class="cellrowborder" valign="top" width="27.560000000000002%" headers="mcps1.2.5.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.2.5.1.3 "><p>0</p>
    </td>
    <td class="cellrowborder" valign="top" width="35.33%" headers="mcps1.2.5.1.4 "><p>指定当前动画的运行时长(单位毫秒)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="18.89%" headers="mcps1.2.5.1.1 "><p>easing</p>
    </td>
    <td class="cellrowborder" valign="top" width="27.560000000000002%" headers="mcps1.2.5.1.2 "><p>string</p>
    </td>
    <td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.2.5.1.3 "><p>linear</p>
    </td>
    <td class="cellrowborder" valign="top" width="35.33%" headers="mcps1.2.5.1.4 "><p>描述动画的时间曲线,支持类型见<a href="#table12317161054">easing有效值说明</a>。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="18.89%" headers="mcps1.2.5.1.1 "><p>delay</p>
    </td>
    <td class="cellrowborder" valign="top" width="27.560000000000002%" headers="mcps1.2.5.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.2.5.1.3 "><p>0</p>
    </td>
    <td class="cellrowborder" valign="top" width="35.33%" headers="mcps1.2.5.1.4 "><p>设置动画执行的延迟时间(默认值表示无延迟)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="18.89%" headers="mcps1.2.5.1.1 "><p>iterations</p>
    </td>
    <td class="cellrowborder" valign="top" width="27.560000000000002%" headers="mcps1.2.5.1.2 "><p>number | string</p>
    </td>
    <td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.2.5.1.3 "><p>1</p>
    </td>
    <td class="cellrowborder" valign="top" width="35.33%" headers="mcps1.2.5.1.4 "><p>设置动画执行的次数。number表示固定次数,Infinity枚举表示无限次数播放。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="18.89%" headers="mcps1.2.5.1.1 "><p>direction<sup>6+</sup></p>
    </td>
    <td class="cellrowborder" valign="top" width="27.560000000000002%" headers="mcps1.2.5.1.2 "><p>string</p>
    </td>
    <td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.2.5.1.3 "><p>normal</p>
    </td>
    <td class="cellrowborder" valign="top" width="35.33%" headers="mcps1.2.5.1.4 "><p>指定动画的播放模式:</p>
    <p>normal: 动画正向循环播放;</p>
    <p>reverse: 动画反向循环播放;</p>
    <p>alternate:动画交替循环播放,奇数次正向播放,偶数次反向播放;</p>
    <p>alternate-reverse:动画反向交替循环播放,奇数次反向播放,偶数次正向播放。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="18.89%" headers="mcps1.2.5.1.1 "><p>fill</p>
    </td>
    <td class="cellrowborder" valign="top" width="27.560000000000002%" headers="mcps1.2.5.1.2 "><p>string</p>
    </td>
    <td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.2.5.1.3 "><p>none</p>
    </td>
    <td class="cellrowborder" valign="top" width="35.33%" headers="mcps1.2.5.1.4 "><p>指定动画开始和结束的状态:</p>
    <p>none:在动画执行之前和之后都不会应用任何样式到目标上。</p>
    <p>forwards:在动画结束后,目标将保留动画结束时的状态(在最后一个关键帧中定义)。</p>
    <p>backwards<sup>6+</sup>:动画将在animation-delay期间应用第一个关键帧中定义的值。当animation-direction为"normal"或"alternate"时应用from关键帧中的值,当animation-direction为"reverse"或"alternate-reverse"时应用to关键帧中的值。</p>
    <p>both<sup>6+</sup>:动画将遵循forwards和backwards的规则,从而在两个方向上扩展动画属性。</p>
    </td>
    </tr>
    </tbody>
    </table>

    **表 4**  easing有效值说明

    <a name="table12317161054"></a>
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="37.940000000000005%" id="mcps1.2.3.1.1"><p>值</p>
    </th>
    <th class="cellrowborder" valign="top" width="62.06%" id="mcps1.2.3.1.2"><p>描述</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>linear</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>动画线性变化。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>ease-in</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>动画速度先慢后快,cubic-bezier(0.42, 0.0, 1.0, 1.0)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>ease-out</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>动画速度先快后慢,cubic-bezier(0.0, 0.0, 0.58, 1.0)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>ease-in-out</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>动画先加速后减速,cubic-bezier(0.42, 0.0, 0.58, 1.0)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>friction</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>阻尼曲线,cubic-bezier(0.2, 0.0, 0.2, 1.0)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>extreme-deceleration</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>急缓曲线,cubic-bezier(0.0, 0.0, 0.0, 1.0)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>sharp</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>锐利曲线,cubic-bezier(0.33, 0.0, 0.67, 1.0)。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>rhythm</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>节奏曲线,cubic-bezier(0.7, 0.0, 0.2, 1.0)。</p>
Z
zengyawen 已提交
280
    </td>
Z
zengyawen 已提交
281 282
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>smooth</p>
Z
zengyawen 已提交
283
    </td>
Z
zengyawen 已提交
284
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>平滑曲线,cubic-bezier(0.4, 0.0, 0.4, 1.0)。</p>
Z
zengyawen 已提交
285 286
    </td>
    </tr>
Z
zengyawen 已提交
287 288 289
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>cubic-bezier(x1, y1, x2, y2)</p>
    </td>
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>在三次贝塞尔函数中定义动画变化过程,入参的x和y值必须处于0-1之间。</p>
Z
zengyawen 已提交
290
    </td>
Z
zengyawen 已提交
291 292
    </tr>
    <tr><td class="cellrowborder" valign="top" width="37.940000000000005%" headers="mcps1.2.3.1.1 "><p>steps(number, step-position)<sup>6+</sup></p>
Z
zengyawen 已提交
293
    </td>
Z
zengyawen 已提交
294 295 296
    <td class="cellrowborder" valign="top" width="62.06%" headers="mcps1.2.3.1.2 "><p>Step曲线。</p>
    <p>number必须设置,支持的类型为int。</p>
    <p>step-position参数可选,支持设置start或end,默认值为end。</p>
Z
zengyawen 已提交
297 298
    </td>
    </tr>
Z
zengyawen 已提交
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
    </tbody>
    </table>

-   返回值

    animation对象属性:

    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="16.48%" id="mcps1.1.4.1.1"><p>属性</p>
    </th>
    <th class="cellrowborder" valign="top" width="20.46%" id="mcps1.1.4.1.2"><p>类型</p>
    </th>
    <th class="cellrowborder" valign="top" width="63.06%" id="mcps1.1.4.1.3"><p>说明</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="16.48%" headers="mcps1.1.4.1.1 "><p>finished</p>
Z
zengyawen 已提交
315
    </td>
Z
zengyawen 已提交
316
    <td class="cellrowborder" valign="top" width="20.46%" headers="mcps1.1.4.1.2 "><p>boolean</p>
Z
zengyawen 已提交
317
    </td>
Z
zengyawen 已提交
318
    <td class="cellrowborder" valign="top" width="63.06%" headers="mcps1.1.4.1.3 "><p>只读,用于表示当前动画是否已播放完成。</p>
Z
zengyawen 已提交
319 320
    </td>
    </tr>
Z
zengyawen 已提交
321
    <tr><td class="cellrowborder" valign="top" width="16.48%" headers="mcps1.1.4.1.1 "><p>pending</p>
Z
zengyawen 已提交
322
    </td>
Z
zengyawen 已提交
323
    <td class="cellrowborder" valign="top" width="20.46%" headers="mcps1.1.4.1.2 "><p>boolean</p>
Z
zengyawen 已提交
324
    </td>
Z
zengyawen 已提交
325
    <td class="cellrowborder" valign="top" width="63.06%" headers="mcps1.1.4.1.3 "><p>只读,用于表示当前动画是否处于等待其他异步操作完成的等待状态(例如启动一个延时播放的动画)。</p>
Z
zengyawen 已提交
326 327
    </td>
    </tr>
Z
zengyawen 已提交
328
    <tr><td class="cellrowborder" valign="top" width="16.48%" headers="mcps1.1.4.1.1 "><p>playState</p>
Z
zengyawen 已提交
329
    </td>
Z
zengyawen 已提交
330
    <td class="cellrowborder" valign="top" width="20.46%" headers="mcps1.1.4.1.2 "><p>string</p>
Z
zengyawen 已提交
331
    </td>
Z
zengyawen 已提交
332 333 334 335 336 337 338 339 340
    <td class="cellrowborder" valign="top" width="63.06%" headers="mcps1.1.4.1.3 "><p>可读可写,动画的执行状态:</p>
    <ul><li>idle:未执行状态,包括已结束或未开始。</li><li>running:动画正在运行。</li><li>paused:动画暂停。</li><li>finished:动画播放完成。</li></ul>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="16.48%" headers="mcps1.1.4.1.1 "><p>startTime</p>
    </td>
    <td class="cellrowborder" valign="top" width="20.46%" headers="mcps1.1.4.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="63.06%" headers="mcps1.1.4.1.3 "><p>可读可写,动画播放开始的预定时间,用途类似于options参数中的delay。</p>
Z
zengyawen 已提交
341 342 343 344 345
    </td>
    </tr>
    </tbody>
    </table>

Z
zengyawen 已提交
346
    animation对象方法:
Z
zengyawen 已提交
347

Z
zengyawen 已提交
348 349 350
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="30.86%" id="mcps1.1.4.1.1"><p>方法</p>
    </th>
    <th class="cellrowborder" valign="top" width="10.58%" id="mcps1.1.4.1.2"><p>参数</p>
Z
zengyawen 已提交
351
    </th>
Z
zengyawen 已提交
352
    <th class="cellrowborder" valign="top" width="58.56%" id="mcps1.1.4.1.3"><p>说明</p>
Z
zengyawen 已提交
353 354 355
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
356
    <tbody><tr><td class="cellrowborder" valign="top" width="30.86%" headers="mcps1.1.4.1.1 "><p>play</p>
Z
zengyawen 已提交
357
    </td>
Z
zengyawen 已提交
358 359 360
    <td class="cellrowborder" valign="top" width="10.58%" headers="mcps1.1.4.1.2 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="58.56%" headers="mcps1.1.4.1.3 "><p>组件播放动画。</p>
Z
zengyawen 已提交
361 362
    </td>
    </tr>
Z
zengyawen 已提交
363 364 365
    <tr><td class="cellrowborder" valign="top" width="30.86%" headers="mcps1.1.4.1.1 "><p>finish</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.58%" headers="mcps1.1.4.1.2 "><p>-</p>
Z
zengyawen 已提交
366
    </td>
Z
zengyawen 已提交
367
    <td class="cellrowborder" valign="top" width="58.56%" headers="mcps1.1.4.1.3 "><p>组件完成动画。</p>
Z
zengyawen 已提交
368 369
    </td>
    </tr>
Z
zengyawen 已提交
370
    <tr><td class="cellrowborder" valign="top" width="30.86%" headers="mcps1.1.4.1.1 "><p>pause</p>
Z
zengyawen 已提交
371
    </td>
Z
zengyawen 已提交
372 373 374
    <td class="cellrowborder" valign="top" width="10.58%" headers="mcps1.1.4.1.2 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="58.56%" headers="mcps1.1.4.1.3 "><p>组件暂停动画。</p>
Z
zengyawen 已提交
375 376
    </td>
    </tr>
Z
zengyawen 已提交
377 378 379
    <tr><td class="cellrowborder" valign="top" width="30.86%" headers="mcps1.1.4.1.1 "><p>cancel</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.58%" headers="mcps1.1.4.1.2 "><p>-</p>
Z
zengyawen 已提交
380
    </td>
Z
zengyawen 已提交
381 382 383 384 385 386 387 388
    <td class="cellrowborder" valign="top" width="58.56%" headers="mcps1.1.4.1.3 "><p>组件取消动画。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="30.86%" headers="mcps1.1.4.1.1 "><p>reverse</p>
    </td>
    <td class="cellrowborder" valign="top" width="10.58%" headers="mcps1.1.4.1.2 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="58.56%" headers="mcps1.1.4.1.3 "><p>组件倒播动画。</p>
Z
zengyawen 已提交
389 390 391 392 393
    </td>
    </tr>
    </tbody>
    </table>

Z
zengyawen 已提交
394
    animation对象事件:
Z
zengyawen 已提交
395

Z
zengyawen 已提交
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
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="20.79%" id="mcps1.1.3.1.1"><p>事件</p>
    </th>
    <th class="cellrowborder" valign="top" width="79.21000000000001%" id="mcps1.1.3.1.2"><p>说明</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="20.79%" headers="mcps1.1.3.1.1 "><p>start<sup><span>6+</span></sup></p>
    </td>
    <td class="cellrowborder" valign="top" width="79.21000000000001%" headers="mcps1.1.3.1.2 "><p>动画开始事件。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="20.79%" headers="mcps1.1.3.1.1 "><p>cancel</p>
    </td>
    <td class="cellrowborder" valign="top" width="79.21000000000001%" headers="mcps1.1.3.1.2 "><p>动画被强制取消。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="20.79%" headers="mcps1.1.3.1.1 "><p>finish</p>
    </td>
    <td class="cellrowborder" valign="top" width="79.21000000000001%" headers="mcps1.1.3.1.2 "><p>动画播放完成。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="20.79%" headers="mcps1.1.3.1.1 "><p>repeat</p>
    </td>
    <td class="cellrowborder" valign="top" width="79.21000000000001%" headers="mcps1.1.3.1.2 "><p>动画重播事件。</p>
    </td>
    </tr>
    </tbody>
    </table>

-   示例
Z
zengyawen 已提交
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

    ```
    <!-- xxx.hml -->
    <div class="container">
      <div id="idName" class="box"></div>
      <div class="buttonBox">
        <button @click="start">
          start
        </button>
        <button @click="cancel">
          cancels
        </button>
      </div>
    </div>
    ```

    ```
    /* xxx.css */
    .container {
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 100%;
    }
    .box{
      width: 200px;
      height: 200px;
      background-color: #ff0000;
      margin-top: 30px;
    }
    .buttonBox{
      margin-top: 30px;
      width: 250px;
      justify-content: space-between;
    }
    button{
      background-color: #8e8b89;
      color: white;
      width: 100px;
      height: 40px;
      font-size: 24px;
    }
    ```

    ```
    // xxx.js
    import prompt from '@system.prompt';
    export default{
      data:{
        animation:'',
      },
      onInit(){
      },
      onShow(){
        var options = {
          duration: 1500,
          easing: 'friction',
          delay: 500,
          fill: 'forwards',
          iterations: 2,
          direction: 'normal',
        };
        var frames = [
          {transform: {translate: '-120px -0px'}, opacity: 0.1, offset: 0.0},
          {transform: {translate: '120px 0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.animation = this.$element('idName').animate(frames, options);
        // handle finish event
        this.animation.onfinish = function(){
          prompt.showToast({
            message: "The animation is finished."
          });
        };
        // handle cancel event
        this.animation.oncancel = function(){
          prompt.showToast({
            message: "The animation is canceled."
          });
        };
        // handle repeat event
        this.animation.onrepeat = function(){
           prompt.showToast({
              message: "The animation is repeated."
           });
        };
      },
      start(){
        this.animation.play();
      },
      cancel(){
        this.animation.cancel();
      }
    }
    ```

    ![](figures/AnimationAPI裁剪.gif)


Z
zengyawen 已提交
524 525 526
## getBoundingClientRect<a name="section11967381328"></a>

getBoundingClientRect\(\):  [ <Rect\>](#table1650917111414)
Z
zengyawen 已提交
527 528 529

获取元素的大小及其相对于窗口的位置。

Z
zengyawen 已提交
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
-   返回值

    **表 5**  Rect对象说明<sup>6+</sup>

    <a name="table1650917111414"></a>
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p>属性</p>
    </th>
    <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p>类型</p>
    </th>
    <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p>描述</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p>width</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p>该元素的宽度。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p>height</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p>该元素的高度。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p>left</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p>该元素左边界距离窗口的偏移。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p>top</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p>number</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p>该元素上边界距离窗口的偏移。</p>
    </td>
    </tr>
    </tbody>
    </table>

Z
zengyawen 已提交
574 575 576 577 578 579 580 581 582
-   示例

    ```
    // xxx.js
    var rect = this.$element('id').getBoundingClientRect();
    console.info(`current element position is ${rect.left}, ${rect.top}`);
    ```


Z
zengyawen 已提交
583 584
## createIntersectionObserver<a name="section7425195215615"></a>

585
createIntersectionObserver\(param?:ObserverParam\): Observer)
Z
zengyawen 已提交
586 587 588

监听元素在当前页面的可见范围。

Z
zengyawen 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601 602
-   参数

    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="19.2%" id="mcps1.1.5.1.1"><p>参数名</p>
    </th>
    <th class="cellrowborder" valign="top" width="17.1%" id="mcps1.1.5.1.2"><p>参数类型</p>
    </th>
    <th class="cellrowborder" valign="top" width="7.5200000000000005%" id="mcps1.1.5.1.3"><p>必填</p>
    </th>
    <th class="cellrowborder" valign="top" width="56.18%" id="mcps1.1.5.1.4"><p>描述</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="19.2%" headers="mcps1.1.5.1.1 "><p>param</p>
    </td>
603
    <td class="cellrowborder" valign="top" width="17.1%" headers="mcps1.1.5.1.2 "><p>ObserverParam</p>
Z
zengyawen 已提交
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
    </td>
    <td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.5.1.3 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="56.18%" headers="mcps1.1.5.1.4 "><p>获取observer的回调。</p>
    </td>
    </tr>
    </tbody>
    </table>

    **表 6**  ObserverParam对象说明<sup>6+</sup>

    <a name="table1335524911817"></a>
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p>属性</p>
    </th>
    <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p>类型</p>
    </th>
    <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p>描述</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p>ratios</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p>Array&lt;number&gt;</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p>组件超出或小于范围时触发observer的回调。</p>
    </td>
    </tr>
    </tbody>
    </table>

-   返回值

    **表 7**  Observer对象支持的方法<sup>6+</sup>

    <a name="table4506633141711"></a>
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p>方法</p>
    </th>
    <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p>参数</p>
    </th>
    <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p>描述</p>
    </th>
    </tr>
    </thead>
    <tbody><tr><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p>observe</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p>callback: function</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p>开启observer的订阅方法。超出或小于阈值时触发callback。</p>
    </td>
    </tr>
    <tr><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p>unobserve</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p>-</p>
    </td>
    <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p>取消observer的订阅方法。</p>
    </td>
    </tr>
    </tbody>
    </table>

Z
zengyawen 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
-   示例

    ```
    // xxx.js
    let observer = this.$element('broad').createIntersectionObserver({
      ratios: [0.2, 0.5], // number
    });
    
    observer.observe((isVisible, ratio)=> {
        console.info('this element is ' + isVisible + 'ratio is ' + ratio)
    })
    
    observer.unobserve()
    ```