|
| 1 | +<template> |
| 2 | + <div v-bind:style="styles" class="spinner spinner--rotate-square-6"> |
| 3 | + <div v-bind:style="outerStyles" class="inner-square inner-square-1"></div> |
| 4 | + <div v-bind:style="innerStyles" class="inner-square inner-square-2"></div> |
| 5 | + </div> |
| 6 | +</template> |
| 7 | +<script> |
| 8 | +export default { |
| 9 | + props: { |
| 10 | + size: { |
| 11 | + default: '90px' |
| 12 | + }, |
| 13 | + color: { |
| 14 | + default: '#41b883' |
| 15 | + } |
| 16 | + }, |
| 17 | + computed: { |
| 18 | + outerWidth () { |
| 19 | + let size = parseInt(this.size) |
| 20 | + return this.calcWidth(size) |
| 21 | + }, |
| 22 | + outerStyles () { |
| 23 | + let size = this.outerWidth + 'px' |
| 24 | + return { |
| 25 | + border: '2px solid ' + this.color, |
| 26 | + width: size, |
| 27 | + height: size |
| 28 | + } |
| 29 | + }, |
| 30 | + innerStyles () { |
| 31 | + let size = this.calcWidth(this.outerWidth) + 'px' |
| 32 | + return { |
| 33 | + border: '2px solid ' + this.color, |
| 34 | + width: size, |
| 35 | + height: size |
| 36 | + } |
| 37 | + }, |
| 38 | + styles () { |
| 39 | + return { |
| 40 | + width: this.size, |
| 41 | + height: this.size |
| 42 | + } |
| 43 | + } |
| 44 | + }, |
| 45 | + methods: { |
| 46 | + calcWidth (outerWidth) { |
| 47 | + let r = 45 * Math.PI / 180 |
| 48 | + let s = Math.abs(Math.cos(r)) |
| 49 | + let c = Math.abs(Math.sin(r)) |
| 50 | + return (outerWidth * c - outerWidth * s) / (Math.pow(c, 2) - Math.pow(s, 2)) |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +</script> |
| 55 | +<style lang="scss" scoped> |
| 56 | + .spinner{ |
| 57 | + position: relative; |
| 58 | + display: flex; |
| 59 | + justify-content: center; |
| 60 | + align-items: center; |
| 61 | + .inner-square { |
| 62 | + content: ""; |
| 63 | + position: absolute; |
| 64 | + width: 30px; |
| 65 | + height: 30px; |
| 66 | + } |
| 67 | + .inner-square-1 { |
| 68 | + animation: spinner--rotate-square-6 2.5s linear infinite; |
| 69 | + } |
| 70 | + .inner-square-2 { |
| 71 | + width: 44px; |
| 72 | + height: 44px; |
| 73 | + animation: spinner--rotate-square-6 2.5s linear infinite; |
| 74 | + animation-direction: reverse; |
| 75 | + } |
| 76 | + } |
| 77 | + @keyframes spinner--rotate-square-6 { |
| 78 | + from { |
| 79 | + -webkit-transform: rotate(0deg); |
| 80 | + transform: rotate(0deg); |
| 81 | + } |
| 82 | + to { |
| 83 | + -webkit-transform: rotate(360deg); |
| 84 | + transform: rotate(360deg); |
| 85 | + } |
| 86 | + } |
| 87 | +</style> |
0 commit comments