CSS3如何实现雷达扫描图(动态样式)


动态样式控制雷达扫描和暂停:

javascript 复制代码
//html部分:
<view class="radar" :style="{'--state':animationPlayState}"></view>
javascript 复制代码
data部分:
animationPlayState: 'paused',
methods:
changeStatus(){
	this.animationPlayState = 'running'
}
javascript 复制代码
//css部分
.radar {
	background:
		-webkit-radial-gradient(center, rgba(32, 255, 77, 0.3) 0%, rgba(32, 255, 77, 0) 75%),
		-webkit-repeating-radial-gradient(rgba(32, 255, 77, 0) 5.8%, rgba(32, 255, 77, 0) 18%, #20ff4d 18.6%, rgba(32, 255, 77, 0) 18.9%),
		-webkit-linear-gradient(90deg, rgba(32, 255, 77, 0) 49.5%, #20ff4d 50%, rgba(32, 255, 77, 0) 50.2%),
		-webkit-linear-gradient(0deg, rgba(32, 255, 77, 0) 49.5%, #20ff4d 50%, rgba(32, 255, 77, 0) 50.2%);
	width: 50vw;
	height: 50vw;
	max-height: 50vw;
	max-width: 50vw;
	position: relative;
	left: 50%;
	top: 35%;
	/* 元素居中定位 */
	transform: translate(-50%, -50%);
	border-radius: 50%;
	// border: 0.2rem solid #20ff4d;
	overflow: hidden;
}

.radar:before {
	content: ' ';
	display: block;
	position: absolute;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	animation: blips 5s infinite;
	animation-timing-function: linear;
	animation-delay: 1.4s;
}

.radar:after {
	content: ' ';
	display: block;
	background-image: linear-gradient(44deg, rgba(0, 255, 51, 0) 50%, #00ff33 100%);
	width: 50%;
	height: 50%;
	position: absolute;
	top: 0;
	left: 0;
	animation: radar-beam 5s infinite;
	/* 速度相同 */
	animation-timing-function: linear;
	transform-origin: bottom right;
	border-radius: 100% 0 0 0;
	animation-play-state: var(--state);
}

@keyframes radar-beam {
	0% {
		transform: rotate(0deg);
	}

	100% {
		transform: rotate(360deg);
	}
}

@keyframes blips {
	14% {
		background: radial-gradient(2vmin circle at 75% 70%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%);
	}

	14.0002% {
		background: radial-gradient(2vmin circle at 75% 70%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%), radial-gradient(2vmin circle at 63% 72%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%);
	}

	25% {
		background: radial-gradient(2vmin circle at 75% 70%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%), radial-gradient(2vmin circle at 63% 72%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%), radial-gradient(2vmin circle at 56% 86%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%);
	}

	26% {
		background: radial-gradient(2vmin circle at 75% 70%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%), radial-gradient(2vmin circle at 63% 72%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%), radial-gradient(2vmin circle at 56% 86%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%);
		opacity: 1;
	}

	100% {
		background: radial-gradient(2vmin circle at 75% 70%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%), radial-gradient(2vmin circle at 63% 72%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%), radial-gradient(2vmin circle at 56% 86%, #ffffff 10%, #20ff4d 30%, rgba(255, 255, 255, 0) 100%);
		opacity: 0;
	}
}

创建一个雷达动画效果 ,具体解释如下:

1.首先定义了一个名为.radar的类,设置了其背景为径向渐变,包括四个部分:中心渐变、重复径向渐变、线性渐变和另一个线性渐变。同时设置了宽度、高度、最大宽度、最大高度、位置(相对定位)、居中对齐、边框圆角和溢出隐藏。

2.接下来定义了.radar:before伪元素,设置了内容为空格、显示方式为块级元素、绝对定位、宽度、高度、边框圆角和动画属性。动画名称为blips,持续时间为5秒,循环次数为无限次,动画速度函数为线性,动画延迟为1.4秒。

3.然后定义了.radar:after伪元素,设置了内容为空格、显示方式为块级元素、背景图片为线性渐变、宽度、高度、绝对定位、顶部、左侧对齐、动画属性。动画名称为radar-beam,持续时间为5秒,循环次数为无限次,动画速度函数为线性,变换原点为右下角,边框圆角为100% 0 0 0,动画播放状态由变量--state控制。

4.最后定义了两个关键帧动画:radar-beam和blips。radar-beam的关键帧动画在0%时设置旋转角度为0度,在100%时设置旋转角度为360度。blips的关键帧动画在不同百分比时设置了不同的背景径向渐变和透明度。

参考:https://www.yisu.com/jc/400058.html

相关推荐
用户1456775610375 分钟前
亲测好用!简单实用的图片尺寸调整工具
前端
索西引擎7 分钟前
npm、yarn、pnpm
前端·npm·node.js
java水泥工41 分钟前
酒店客房管理系统|基于SpringBoot和Vue的酒店客房管理系统(源码+数据库+文档)
spring boot·vue·酒店管理系统·酒店客房管理系统
天生我材必有用_吴用1 小时前
Vue3 + VitePress 搭建组件库文档平台(结合 Element Plus 与 Arco Design Vue)—— 超详细图文教程
前端
liu****1 小时前
基于websocket的多用户网页五子棋(八)
服务器·前端·javascript·数据库·c++·websocket·个人开发
San301 小时前
深入理解 JavaScript 函数:从基础到高阶应用
前端·javascript·node.js
ttyyttemo1 小时前
Column,rememberScrollState,记住滚动位置
前端
芒果茶叶2 小时前
并行SSR,SSR并行加载
前端·javascript·架构
vortex52 小时前
解决 Kali 中 Firefox 下载语言包和插件速度慢的问题:配置国内镜像加速
前端·firefox·腾讯云
修仙的人2 小时前
Rust + WebAssembly 实战!别再听说,学会使用!
前端·rust