网站首页 > 文章精选 正文
Html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>转动的风扇</title>
<link rel="stylesheet" href="../css/20241114.css">
</head>
<body>
<div class="main">
<img src="image/20241114/fan-blade.png" alt="" srcset="">
<button onclick="fanOn()">ON </button>
<button onclick="fanOff()">OFF</button>
<button onclick="fanBtn1()">1</button>
<button onclick="fanBtn2()">2</button>
<button onclick="fanBtn3()">3</button>
</div>
<script src="../js/20241114.js"></script>
</body>
</html>
Css:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
img{
padding: 50px;
border-radius: 50%;
animation: fananim linear infinite;
}
@keyframes fananim {
100%
{
transform: rotate(360deg);
}
}
button{
width: 100px;
height: 100px;
padding: 20px 30px;
margin: 0 20px;
font-size: 25px;
font-weight: 550;
border: none;
background-color: silver;
border-radius: 50%;
transition: 0.1s;
}
.main button:nth-last-child(5){
background-color: rgb(0, 255, 0);
}
.main button:nth-last-child(4){
background-color: rgb(255, 0, 0);
}
button:active{
box-shadow: 0px 10px 10px black;
transform: scale(0.95);
}
Js:
let fan_img = document.querySelector("img");
function fanOn(){
fan_img.style.animationDuration = 3+"s";
}
function fanOff(){
fan_img.style.animationDuration = 0+"s";
}
function fanBtn1(){
fan_img.style.animationDuration = 1+"s";
}
function fanBtn2(){
fan_img.style.animationDuration = 0.5+"s";
}
function fanBtn3(){
fan_img.style.animationDuration = 0.1+"s";
}
通过按钮点击事件,调用JavaScript方法,风扇图片的动画会以 1 秒的持续时间进行播放。
animationDuration 属性定义了动画一个周期的持续时间
猜你喜欢
- 2025-01-14 2014年最优秀JavaScript编辑器大盘点
- 2025-01-14 三年级数学下册:第四单元试卷附答案(可下载打印)
- 2025-01-14 在浏览器中进行深度学习:TensorFlow.js (五)构建一个神经网络
- 2025-01-14 【JS逆向百例】酷某音乐 wasm 逆向
- 2025-01-14 JavaScript巩固基础每日随记之[数组]
- 2025-01-14 TensorFlow.js,让你的应用更加高级,更具逼格
- 2025-01-14 Web前端学习6个有效果软件!看看哪些你用的上
- 2025-01-14 每日JS逆向练习之斗鱼登录密码加密,今天你逆了吗?
- 2025-01-14 Node.js基于Linux安装步骤
- 2025-01-14 JavaScript求数组最大值、最小值和平均数的几种常用方法
- 最近发表
- 标签列表
-
- newcoder (56)
- 字符串的长度是指 (45)
- drawcontours()参数说明 (60)
- unsignedshortint (59)
- postman并发请求 (47)
- python列表删除 (50)
- 左程云什么水平 (56)
- 计算机网络的拓扑结构是指() (45)
- 稳压管的稳压区是工作在什么区 (45)
- 编程题 (64)
- postgresql默认端口 (66)
- 数据库的概念模型独立于 (48)
- 产生系统死锁的原因可能是由于 (51)
- 数据库中只存放视图的 (62)
- 在vi中退出不保存的命令是 (53)
- 哪个命令可以将普通用户转换成超级用户 (49)
- noscript标签的作用 (48)
- 联合利华网申 (49)
- swagger和postman (46)
- 结构化程序设计主要强调 (53)
- 172.1 (57)
- apipostwebsocket (47)
- 唯品会后台 (61)
- 简历助手 (56)
- offshow (61)