SVG动画边框

 

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
xml:space="preserve" class="circle-load-rect-svg" width="300" height="200" 
viewbox="0 0 600 400">
    <polyline points="5 5, 575 5, 575 200, 5 200" class="g-rect-path"/>
    <polyline points="5 5, 575 5, 575 200, 5 200" class="g-rect-fill"/>
</svg>

version: 表示 <svg> 的版本,目前只有 1.0,1.1 两种

xmlns:http://www.w3.org/2000/svg 固定值

xmlns:xlink:http://www.w3.org/1999/xlink 固定值

xml:space:preserve 固定值,上述三个值固定,表示命名空间,当数据单独存在svg文件内时,这3个值不能省略

class:就是我们熟悉的 class

width | height: 定义 svg 画布的大小

viewbox: 定义了画布上可以显示的区域,当 viewBox 的大小和 svg 不同时,viewBox 在屏幕上的显示会缩放至 svg 同等大小(暂时可以不用理解)

stroke-dasharray用来设置虚线,用“,”分隔的数字表示“实线,空”,stroke-dasharray=”5, 5” 。如果数字是奇数个的话,则自动补充为偶数。如 stroke-dasharray=”5,3,2” 实际为 “5,3,2,5,3,2”.

stroke-dashoffset用来表示偏移。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>svg边框动画特效</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>

<div id="workarea">

		<div class="svg-wrapper" style="position:absolute;top:200px;left:200px; border:1px solid red;">
			<svg height="193" width="540" >
				<rect id="shape" height="193" width="540" />
				
			</svg>
		</div>

</div>


</body>
</html>

 style.css

@charset "utf-8";



#workarea{position:absolute;width:100%;height:100%;background-color:#1e1a3e;font-family:Raleway}

#shape{
	stroke-width:6px;
	fill:transparent;
	stroke:#009FFD;
	stroke-dasharray:83 650;
	stroke-dashoffset:0;
  -webkit-animation: draw 2s linear infinite;
  animation: draw 2s linear infinite;
}

@-webkit-keyframes draw {
  to {
     stroke-dashoffset:733;
  }
 
}

@keyframes draw {
  to {
     stroke-dashoffset:733;
  }
}

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现类似于 `dashed` 边框的环形效果,可以使用 SVG 的 `stroke-dasharray` 和 `stroke-dashoffset` 属性,配合 CSS 的动画效果来创建。 以下是一个示例代码: ```html <svg viewBox="0 0 100 100"> <circle cx="50" cy="50" r="40" stroke="#ccc" fill="none" stroke-width="10" stroke-dasharray="251.2" stroke-dashoffset="251.2" class="circle" /> </svg> ``` ```css .circle { stroke-dasharray: 251.2; stroke-dashoffset: 251.2; animation: dash 2s linear forwards; } @keyframes dash { to { stroke-dashoffset: 0; } } ``` 解释一下代码: - `<circle>` 标签用于创建一个圆,其中 `cx` 和 `cy` 属性指定圆心坐标,`r` 属性指定半径,`stroke` 属性指定边框颜色,`fill` 属性指定填充颜色,这里为透明色,`stroke-width` 属性指定边框宽度。 - `stroke-dasharray` 属性指定边框线的长度和间隔,这里设置为 `251.2`(即圆的周长),表示边框线长度为圆的周长,间隔为 0。 - `stroke-dashoffset` 属性指定边框线的起始偏移量,这里设置为 `251.2`,表示边框线从圆的最上方开始画。 - `class` 属性用于给圆添加一个 `circle` 类名,用于 CSS 选择器。 - CSS 中,使用 `animation` 属性来定义动画效果,其中 `dash` 是动画名称,`2s` 是动画时长,`linear` 是动画速度曲线,`forwards` 表示动画结束后保持最后一帧的状态。 - `@keyframes` 规则用于定义动画的具体过程,这里从 `to` 开始,表示动画从开始到结束,`stroke-dashoffset` 属性从 `251.2` 减少到 0,即边框线从圆的最上方逆时针绘制到完整的圆形。 你可以根据需要调整圆的大小、颜色、宽度、动画时长等属性,从而得到不同的环形效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值