分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

css3 雪碧图实现数字切换

发布时间:2023-09-06 01:14责任编辑:赖小花关键词:暂无标签
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 雪碧图实现数字切换

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved