body {
flex-wrap:wrap;
flex:1
}
.flex {
display:flex;
justify-content:center;
align-items:center;
}
.demo {
width:350px;
height:200px;
position:relative;
margin:50px;
background:linear-gradient(90deg,#feac5e,#c779d0,#4bc0c8);
color:#fff;
font-size:30px;
}
.circle {
width:100px;
height:100px;
border-radius:50%;
position:relative;
background:linear-gradient(90deg,#feac5e,#c779d0,#4bc0c8);
color:#fff;
}
.circle:before {
content:'';
position:absolute;
left:0;
top:0;
right:0;
bottom:0;
margin:-6px;
border:5px solid transparent;
border-top:5px solid #f64f59;
border-radius:50%;
transform:rotate(45deg);
animation:circleRotate 3s linear infinite;
}
@keyframes circleRotate {
0% {
transform:rotate(0);
}
100% {
transform:rotate(360deg);
}
}功能:为矩形元素附上一层运动的边线原理: 核心:css clip rect web animation 负责动态化注意:请使用较高版本现代浏览器打开 本代码 使用了es6语法 且并未对css各浏览器前缀做处理 如需兼容低版本浏览器 请自行加 web animate polyfill 及 使用babel转译author: 胡洋洋 time: 2019-03-16
//纯 js实现动态边框效果
//根据 http://www.jq22.com/jquery-info3297 bee木头 作者 核心思路(css clip rect) 创作
//传入依赖元素 自动生成动态边框
/* 使用_initdanceborder(el,option);*/
//默认设置 尺寸单位均为px
let _options = { //边框模糊度
blur: 1, //距依赖元素距离
margin: -5, //边框宽度
borderwidth: 4, //转一周时长
duration: 8000, //运动效果
default: 匀速
easing: 'linear', //是否两条运动线 默认两条
double: true, //渐变色边框 优先级高 若使用渐变色或图片背景 请正确传入该值 否则边框不会显示
'border-image': 'linear-gradient(to bottom right, #12c2e9,#c471ed,#f64f59) 10 10', //边框色border - image 优先级低 'border-color': 'green'
}