概述
小程序商城或者 web 端网站时,我们可以只通过 CSS 的 animation
和transform
,而不需要借助额外的第三方库轻松实现简单的动画效果,丰富页面的表达效果
效果
如下图所示,点击按钮就会有个商品进入左下角的购物车内
购物车动画示例地址
代码示例
元素
开始只需要写按钮和购物车两个 DOM
节点
<button id="btn">add</button>
<span class="bulk">
<svg
t="1724755384446"
class="icon"
viewBox="0 0 1028 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
p-id="4635"
width="20"
height="20"
>
<path
d="M332.8 790.528q19.456 0 36.864 7.168t30.208 19.968 20.48 30.208 7.68 36.864-7.68 36.864-20.48 30.208-30.208 20.48-36.864 7.68q-20.48 0-37.888-7.68t-30.208-20.48-20.48-30.208-7.68-36.864 7.68-36.864 20.48-30.208 30.208-19.968 37.888-7.168zM758.784 792.576q19.456 0 37.376 7.168t30.72 19.968 20.48 30.208 7.68 36.864-7.68 36.864-20.48 30.208-30.72 20.48-37.376 7.68-36.864-7.68-30.208-20.48-20.48-30.208-7.68-36.864 7.68-36.864 20.48-30.208 30.208-19.968 36.864-7.168zM930.816 210.944q28.672 0 44.544 7.68t22.528 18.944 6.144 24.064-3.584 22.016-13.312 37.888-22.016 62.976-23.552 68.096-18.944 53.248q-13.312 40.96-33.28 56.832t-49.664 15.872l-35.84 0-65.536 0-86.016 0-96.256 0-253.952 0 14.336 92.16 517.12 0q49.152 0 49.152 41.984 0 20.48-9.728 35.84t-38.4 14.336l-49.152 0-94.208 0-118.784 0-119.808 0-99.328 0-55.296 0q-20.48 0-34.304-9.216t-23.04-24.064-14.848-32.256-8.704-32.768q-1.024