自定义圆点旋转加载样式

更多样式:点击查看

效果

在这里插入图片描述

模板

<div class="loader">
	<svg viewBox="0 0 80 80">
		<circle r="32" cy="40" cx="40" id="test"></circle>
	</svg>
</div>

<div class="loader">
	<svg viewBox="0 0 80 80">
		<rect height="64" width="64" y="8" x="8"></rect>
	</svg>
</div>

样式

.loader {
	--path: #2f3545;
	--dot: #5628ee;
	--duration: 3s;
	width: 44px;
	height: 44px;
	position: relative;
	display: inline-block;
	margin: 0 16px;

	&:before {
		position: absolute;
		top: 37px;
		left: 19px;
		width: 6px;
		height: 6px;
		content: "";
		border-radius: 50%;
		background: var(--dot);
		transform: translate(-18px, -18px);
		animation: dotRect var(--duration) cubic-bezier(0.785, 0.135, 0.15, 0.86) infinite;
	}

	svg {
		display: block;
		width: 100%;
		height: 100%;

		rect,
		polygon,
		circle {
			fill: none;
			stroke: var(--path);
			stroke-width: 10px;
			stroke-linecap: round;
			stroke-linejoin: round;
		}

		circle {
			stroke-dashoffset: 75;
			animation: pathCircle var(--duration) cubic-bezier(0.785, 0.135, 0.15, 0.86) infinite;
			stroke-dasharray: 150 50 150 50;
		}

		rect {
			stroke-dashoffset: 0;
			animation: pathRect 3s cubic-bezier(0.785, 0.135, 0.15, 0.86) infinite;
			stroke-dasharray: 192 64 192 64;
		}
	}
}

@keyframes dotRect {
	25% {
		transform: translate(0, 0);
	}

	50% {
		transform: translate(18px, -18px);
	}

	75% {
		transform: translate(0, -36px);
	}

	100% {
		transform: translate(-18px, -18px);
	}
}

@keyframes pathRect {
	25% {
		stroke-dashoffset: 64;
	}

	50% {
		stroke-dashoffset: 128;
	}

	75% {
		stroke-dashoffset: 192;
	}

	100% {
		stroke-dashoffset: 256;
	}
}

@keyframes pathCircle {
	25% {
		stroke-dashoffset: 125;
	}

	50% {
		stroke-dashoffset: 175;
	}

	75% {
		stroke-dashoffset: 225;
	}

	100% {
		stroke-dashoffset: 275;
	}
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值