码迷,mamicode.com
首页 > Web开发 > 详细

css3 雪碧图实现数字切换

时间:2017-09-29 21:27:51      阅读:438      评论:0      收藏:0      [点我收藏+]

标签:mil   div   分享   sof   col   time   ++   only   highlight   

vue中css 雪碧图应用及数字切换demo
<template>
<div class="total">
<div class="content">
<span class="number" v-for="item in numberObj" :class="item.classObj"></span>
</div>
</div>
</template>

<script type="text/babel">
export default {
data() {
return {
total: ‘12451‘,
numberObj: [
{
classObj: ‘‘
},
{
classObj: ‘‘
},
{
classObj: ‘‘
},
{
classObj: ‘‘
},
{
classObj: ‘‘
},
{
classObj: ‘‘
},
{
classObj: ‘‘
},
{
classObj: ‘‘
},
{
classObj: ‘‘
}
]
};
},
       mounted() {
    setTimeout(function () {
    this.total = 12451;
    }, 1000 * 30);
    },
    watch: {
    ‘total‘(newVal, oldVal){
    this.total = newVal;
    this.refresh();
    }
    },
    methods: {
    refresh: function () {
    let length = this.total.toString().length;

    for (let i = 1; i <= length; i++) {
    let _number = parseInt(this.total % Math.pow(10, i) / Math.pow(10, (i - 1)));
    this.numberObj[9-i].classObj = [‘position_‘ + _number, ‘highLight‘];
    }
    }
    }
    };
</script>

.number {
flex: none;
margin: 0 2px;
height: 34px;
width: 21px;
background-image: url("/image/number/css-sprites-x1.png");
@media only screen and (min-device-pixel-ratio: 2) {
background-image: url("/image/number/css-sprites-x2.png");
}

&.highLight{
background-image: url("/image/number/css-sprites-highlight-x1.png");
@media only screen and (min-device-pixel-ratio: 2) {
background-image: url("/image/number/css-sprites-highlight-x2.png");
}
}

background-position: 48px 0;

&.position_0 {
background-position: -1px 0;

}
&.position_1 {
background-position: -22px 0;

}
&.position_2 {
background-position: -43px 0;

}
&.position_3 {
background-position: -70px 0;

}
&.position_4 {
background-position: -97px 0;

}
&.position_5 {
background-position: 129px 0;

}
&.position_6 {
background-position: 102px 0;

}
&.position_7 {
background-position: 72px 0;

}
&.position_9 {
background-position: 21px 0;

}
}

效果图:

技术分享 技术分享

css3 雪碧图实现数字切换

标签:mil   div   分享   sof   col   time   ++   only   highlight   

原文地址:http://www.cnblogs.com/apple-p/p/7612377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!