0%

纯CSS生成loading动画的JS插件spin.js

介绍一个很有趣的JS插件,可以生成如下的loading动画,用的是CSS3动画
这个插件使用起来很简单,首先引用插件源代码:spin.js
然后是配置调用代码:



var opts = {
lines: 13, // loading动画的线的数目 The number of lines to draw
length: 20, // 线的长度,值为0时为圆 The length of each line
width: 10, // 线的宽度,粗细 The line thickness
radius: 30, // 线离中心点的距离 The radius of the inner circle
corners: 1, // 线两端的圆角的值,取值范围0-1 Corner roundness (0..1)
rotate: 0, // 整体旋转度数 The rotation offset
direction: 1, // 1: 时钟方向动画, -1: 时钟反方向动画 1: clockwise, -1: counterclockwise
color: ‘#fff’, // 线的颜色#rgb or #rrggbb or array of colors
speed: 1, // 动画速度Rounds per second
trail: 60, // 透明度Afterglow percentage
shadow: false, // 阴影Whether to render a shadow
hwaccel: false, // 使用应用加速Whether to use hardware acceleration
className: ‘spinner’, //父级的class名 The CSS class to assign to the spinner
zIndex: 2e9, // z-index取值The z-index (defaults to 2000000000)
top: ‘auto’, // TOP值,默认父级为relative(Top position relative to parent in px)
left: ‘auto’ // LEFT值,默认父级为relative(Left position relative to parent in px)
};

var target = document.getElementById(‘spin-preview’);
var spinner = new Spinner(opts).spin(target);


<!–

–>

它的官网可以手动自定义各种属性来预览loading动画效果,地址:http://fgnass.github.io/spin.js/