| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <template>
- <div class="count" :class="[changeState, arrow]">
- <span class="current top">{{ nextTime }}</span>
- <span class="next top">{{ time }}</span>
- <span class="current bottom">{{ nextTime }}</span>
- <span class="next bottom">{{ time }}</span>
- </div>
- </template>
- <script setup lang="ts">
- import { computed, ref, watch, toRefs } from 'vue'
- const props = defineProps({
- chartConfig: {
- type: Object,
- required: true
- },
- value: {
- type: Number,
- required: false
- }
- })
- //动态宽高
- const { w, h } = toRefs(props.chartConfig.attr)
- let changeState = ref('')
- let time: any = ref(0) //当前数字
- let nextTime = ref(0) //下一个数字
- let duration = 1000 //延迟时间
- let arrow = 'up' //方向
- watch(
- () => props.value,
- (n: any) => {
- if (typeof n == 'number') selfAdaption(n)
- },
- { deep: true, immediate: true }
- )
- //自适应改变数字
- function selfAdaption(n: any) {
- changeState.value = ''
- setTimeout(() => {
- changeState.value = 'changing'
- }, 20)
- setTimeout(() => {
- changeState.value = 'changed'
- }, duration * 0.9)
- time.value = n
- nextTime.value = n - 1 < 0 ? 0 : n - 1
- }
- // // 倒计时改变
- // function Interval() {
- // setTimeout(() => {
- // changeState.value = ''
- // setTimeout(() => {
- // changeState.value = 'changing'
- // }, 20)
- // setTimeout(() => {
- // changeState.value = 'changed'
- // }, duration * 0.9)
- // if (time.value == 0) arrow = 'up'
- // if (time.value == 9) arrow = 'down'
- // let delta = -1
- // if (arrow == 'up') delta = 1
- // if (arrow == 'down') {
- // if (time.value == 0) {
- // setTimeout(() => {
- // time.value = 9
- // }, 20)
- // }
- // }
- // if (arrow == 'up') {
- // if (time.value == 9) {
- // setTimeout(() => {
- // time.value = 0
- // }, 20)
- // }
- // }
- // time.value += delta
- // nextTime.value = time.value - delta
- // Interval()
- // }, duration)
- // }
- // if (!(typeof props.value == 'number')) {
- // Interval()
- // }
- </script>
- <style lang="less" scoped>
- .count {
- box-shadow: 0 5px 5px -5px rgba(0, 0, 0, 0.2);
- -moz-perspective: 500px;
- -webkit-perspective: 500px;
- perspective: 500px;
- text-align: center;
- -moz-transform: translateZ(0);
- -webkit-transform: translateZ(0);
- transform: translateZ(0);
- width: v-bind('w + "px"');
- height: v-bind('h + "px"');
- line-height: v-bind('h + "px"');
- padding: 15px;
- box-sizing: border-box;
- }
- .count span {
- background: #202020;
- color: #f8f8f8;
- display: block;
- font-size: 50px;
- left: 0;
- position: absolute;
- top: 0;
- text-shadow: 0 1px 0 #282828, 0 2px 0 #1e1e1e, 0 3px 0 #141414, 0 4px 0 #0a0a0a, 0 5px 0 #000,
- 0 0 10px rgba(0, 0, 0, 0.8);
- -moz-transform-origin: 0 v-bind('h / 2 + "px"') 0;
- -webkit-transform-origin: 0 v-bind('h / 2 + "px"') 0;
- transform-origin: 0 v-bind('h / 2 + "px"') 0;
- width: 100%;
- }
- .count span:before {
- border-bottom: 2px solid #000;
- content: '';
- left: 0;
- position: absolute;
- width: 100%;
- }
- .count span:after {
- box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.35);
- content: '';
- height: 100%;
- left: 0;
- position: absolute;
- top: 0;
- width: 100%;
- }
- .count .small {
- font-size: 175px;
- }
- .count .top {
- border-top-left-radius: 11px;
- border-top-right-radius: 11px;
- box-shadow: inset 0 2px rgba(0, 0, 0, 0.9), inset 0 3px 0 rgba(255, 255, 255, 0.4);
- height: 50%;
- overflow: hidden;
- }
- .count .top:before {
- bottom: 0;
- }
- .count .top:after {
- background: -moz-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
- background: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
- background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
- border-top-left-radius: 11px;
- border-top-right-radius: 11px;
- }
- .count .bottom {
- border-radius: 10px;
- height: 100%;
- }
- .count .bottom:before {
- top: 50%;
- }
- .count .bottom:after {
- border-radius: 10px;
- background: -moz-linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0));
- background: -webkit-linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0));
- background: linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0));
- }
- .count.down .top {
- border-top-left-radius: 11px;
- border-top-right-radius: 11px;
- height: 50%;
- }
- .count.down .top.current {
- -moz-transform-style: flat;
- -webkit-transform-style: flat;
- transform-style: flat;
- z-index: 3;
- }
- .count.down .top.next {
- -moz-transform: rotate3d(1, 0, 0, -90deg);
- -ms-transform: rotate3d(1, 0, 0, -90deg);
- -webkit-transform: rotate3d(1, 0, 0, -90deg);
- transform: rotate3d(1, 0, 0, -90deg);
- z-index: 4;
- }
- .count.down .bottom {
- border-radius: 10px;
- }
- .count.down .bottom.current {
- z-index: 2;
- }
- .count.down .bottom.next {
- z-index: 1;
- }
- .count.down.changing .bottom.current {
- box-shadow: 0 75px 5px -20px rgba(0, 0, 0, 0.3);
- -moz-transform: rotate3d(1, 0, 0, 90deg);
- -ms-transform: rotate3d(1, 0, 0, 90deg);
- -webkit-transform: rotate3d(1, 0, 0, 90deg);
- transform: rotate3d(1, 0, 0, 90deg);
- -moz-transition: -moz-transform 0.35s ease-in, box-shadow 0.35s ease-in;
- -o-transition: -o-transform 0.35s ease-in, box-shadow 0.35s ease-in;
- -webkit-transition: -webkit-transform 0.35s ease-in, box-shadow 0.35s ease-in;
- transition: transform 0.35s ease-in, box-shadow 0.35s ease-in;
- }
- .count.down.changing .top.next,
- .count.down.changed .top.next {
- -moz-transition: -moz-transform 0.35s ease-out 0.35s;
- -o-transition: -o-transform 0.35s ease-out 0.35s;
- -webkit-transition: -webkit-transform 0.35s ease-out;
- -webkit-transition-delay: 0.35s;
- transition: transform 0.35s ease-out 0.35s;
- -moz-transform: none;
- -ms-transform: none;
- -webkit-transform: none;
- transform: none;
- }
- .count.up .top {
- height: 50%;
- }
- .count.up .top.current {
- z-index: 4;
- }
- .count.up .top.next {
- z-index: 3;
- }
- .count.up .bottom.current {
- z-index: 1;
- }
- .count.up .bottom.next {
- box-shadow: 0 75px 5px -20px rgba(0, 0, 0, 0.3);
- -moz-transform: rotate3d(1, 0, 0, 90deg);
- -ms-transform: rotate3d(1, 0, 0, 90deg);
- -webkit-transform: rotate3d(1, 0, 0, 90deg);
- transform: rotate3d(1, 0, 0, 90deg);
- z-index: 2;
- }
- .count.up.changing .top.current {
- -moz-transform: rotate3d(1, 0, 0, -90deg);
- -ms-transform: rotate3d(1, 0, 0, -90deg);
- -webkit-transform: rotate3d(1, 0, 0, -90deg);
- transform: rotate3d(1, 0, 0, -90deg);
- -moz-transition: -moz-transform 0.2625s ease-in, box-shadow 0.2625s ease-in;
- -o-transition: -o-transform 0.2625s ease-in, box-shadow 0.2625s ease-in;
- -webkit-transition: -webkit-transform 0.2625s ease-in, box-shadow 0.2625s ease-in;
- transition: transform 0.2625s ease-in, box-shadow 0.2625s ease-in;
- }
- .count.up.changing .bottom.next,
- .count.up.changed .bottom.next {
- box-shadow: 0 0 0 0 transparent;
- -moz-transition: box-shadow 0.175s cubic-bezier(0.375, 1.495, 0.61, 0.78) 0.35s,
- -moz-transform 0.35s cubic-bezier(0.375, 1.495, 0.61, 0.78) 0.35s;
- -o-transition: box-shadow 0.175s cubic-bezier(0.375, 1.495, 0.61, 0.78) 0.35s,
- -o-transform 0.35s cubic-bezier(0.375, 1.495, 0.61, 0.78) 0.35s;
- -webkit-transition: box-shadow 0.175s cubic-bezier(0.375, 1.495, 0.61, 0.78),
- -webkit-transform 0.35s cubic-bezier(0.375, 1.495, 0.61, 0.78);
- -webkit-transition-delay: 0.35s, 0.35s;
- transition: box-shadow 0.175s cubic-bezier(0.375, 1.495, 0.61, 0.78) 0.35s,
- transform 0.35s cubic-bezier(0.375, 1.495, 0.61, 0.78) 0.35s;
- -moz-transform: rotate3d(1, 0, 0, 0);
- -ms-transform: rotate3d(1, 0, 0, 0);
- -webkit-transform: rotate3d(1, 0, 0, 0);
- transform: rotate3d(1, 0, 0, 0);
- }
- .count.changed .top.current,
- .count.changed .bottom.current {
- display: none;
- }
- html,
- body {
- height: 100%;
- width: 100%;
- }
- body {
- background: #202020;
- background-origin: 50% 50%;
- -moz-background-size: cover;
- -o-background-size: cover;
- -webkit-background-size: cover;
- background-size: cover;
- font-family: 'Oswald';
- }
- </style>
|