当前位置: 首页 > news >正文

购物车-多元素组合动画css

学习 渡一课程 多元素组合动画 练习。

在我们开发购物车功能时,经常会有点击添加按钮,就会有一个小圆点掉进购物车的动画,如下图所示,今天我们通过css来实现。

首先实现多元素组合动画

直接上代码,可以复制到本地使用:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>多元素动画</title><style>*{padding: 0;margin: 0;}.view{width: 400px;height: 600px;position: relative;border: 1px solid #dedede;}.ShoppingCart {position: absolute;right: 0;bottom: 0;text-align: center;width: 80px;height: 40px;background-color: blueviolet;color: #ffffff;}.add {position: relative;width: 20px;height: 20px;top:50px;left: 10px;background-color: blue;color: #ffffff;text-align: center;line-height: 20px;cursor: pointer;border-radius: 50%;}.box{position: absolute;top: 0;left: 0;display: none;}.active{display: block;animation: move1 0.6s cubic-bezier(0, 0.36, 1, 0.59);}.ball{width: 20px;height: 20px;top: 0;left: 0;border-radius: 50%;background-color: blue;position: absolute;z-index: -1;}.active .ball{animation: move2 0.6s cubic-bezier(0.35,-0.35, 1, 0.38);}@keyframes move1 {to {transform: translateX(350px);}}@keyframes move2 {to {transform: translateY(510px);}}</style>
</head><body><div class="view"><div class="add" id="add">+<div class="box"><div class="ball"></div></div></div><div class="ShoppingCart">购物车</div></div></body>
<script>    let add = document.querySelector(".add")let box = document.querySelector(".box")add.addEventListener("click",()=>{box.className = "box active"setTimeout(()=>{box.className = "box"},2000)})
</script>
</html>

 实现多个动画

上代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>多种元素动画</title><style>*{padding: 0;margin: 0;}.view{width: 400px;height: 600px;position: relative;border: 1px solid #dedede;}.ShoppingCart {position: absolute;right: 0;bottom: 0;text-align: center;width: 80px;height: 40px;background-color: blueviolet;color: #ffffff;}.add {position: relative;width: 20px;height: 20px;top:50px;left: 10px;background-color: blue;color: #ffffff;text-align: center;line-height: 20px;cursor: pointer;border-radius: 50%;}.box{position: absolute;top: 0;left: 0;animation: move1 0.6s cubic-bezier(0, 0.36, 1, 0.59);}.ball{width: 20px;height: 20px;top: 0;left: 0;border-radius: 50%;background-color: blue;position: absolute;z-index: -1;animation: move2 0.6s cubic-bezier(0.35,-0.35, 1, 0.38);}@keyframes move1 {to {transform: translateX(350px);}}@keyframes move2 {to {transform: translateY(510px);}}</style>
</head><body><div class="view"><div class="add" id="add">+</div><div class="ShoppingCart">购物车</div></div></body>
<script>    let add = document.querySelector(".add")let box = document.querySelector(".box")add.addEventListener("click",()=>{let ele = document.createElement("div")ele.className = "box"ele.innerHTML = "<div class='ball'></div>"add.appendChild(ele)setTimeout(()=>{ele.parentNode.removeChild(ele);},1000)})
</script>
</html>

http://www.lryc.cn/news/480378.html

相关文章:

  • 【计网不挂科】计算机网络期末考试——【选择题&填空题&判断题&简述题】题库(3)
  • [ vulnhub靶机通关篇 ] 渗透测试综合靶场 DarkHole:1 通关详解 (附靶机搭建教程)
  • 【LeetCode】移除链表中等于设定值的元素、反转链表
  • Redis - 主从复制
  • UE5 HLSL 学习笔记
  • 一个简单ASP.NET购物车设计
  • 双向循环列表
  • go项目出现了ambiguous import要怎么解决?
  • 更改Ubuntu22.04锁屏壁纸
  • ROS2humble版本使用colcon构建包
  • CSRF 跨站请求伪造的实现原理和预防措施
  • 【LeetCode】【算法】22. 括号生成
  • WPF+MVVM案例实战与特效(二十五)- 3D粒子波浪效果实现
  • wsl2安装和使用
  • 【划分型 DP-最优划分】【腾讯笔试压轴】【hard】力扣132. 分割回文串 II
  • Kubernetes-镜像加速篇-01-加速工具
  • 字母的异位数
  • 达梦数据库DM Exception字符串截断错误,略坑~
  • vue实现图片无限滚动播放
  • python爬虫指南——初学者避坑篇
  • Vivado+Vscode联合打造verilog环境
  • Python 微服务架构
  • Android JNI 技术入门指南
  • 实在智能受邀出席柳州市智能终端及机器人产业发展合作大会
  • 算法求解(C#)-- 寻找包含目标字符串的最短子串算法
  • AscendC从入门到精通系列(二)基于Kernel直调开发AscendC算子
  • DAO模式的理解
  • 使用GitHub Actions实现CI/CD流程
  • 机器人助力Bridge Champ游戏:1.4.2版本如何提升玩家体验
  • 滑动窗口(单调队列维护窗口)-acwing