vue通知(滚动)

  1. li宽度不顾定

    <template>
    • {{item.name}}
    </template> <script> export default { name: "HelloWorld", data() { return { timer: null, pwidth: 0, left: 0, items: [ { name: "1马dfgdfgs云1马dfgdfgs云1马dfgdfgs云1马dfgdfgs云", active: false }, { name: "2雷dfgd军", active: false }, { name: "3dsfgd张珊", active: false } ] }; },

    mounted() {
    this.setLeft();
    },
    watch: {},
    methods: {
    setLeft() {
    let element = this.$refs.cmdlist;
    this.pwidth = document.defaultView
    .getComputedStyle(element, "")
    .width.split("px");
    this.timer = setInterval(() => {
    this.left--;
    let num = parseInt(this.pwidth[0]);
    if (-num >= this.left) {
    console.log("this.left", this.left);
    console.log("-num", -num);
    this.left = 0;
    }
    }, 30);
    },
    clearLeft() {
    if (this.timer) clearInterval(this.timer);
    }
    },
    beforeDestroy() {
    if (this.timer) clearInterval(this.timer);
    }
    };
    </script>

    <style scoped> * { margin: 0; padding: 0; } #app { margin-top: 60px; margin-left: 200px; text-align: center; } #box { width: 600px; height: 50px; overflow: hidden; border: 1px solid #090; } ul { padding: 0px; margin: 0px; display: flex; /* width: 320px; */ height: 50px; border: 1px solid #f00; } li { list-style: none; padding: 0px; margin: 0px; /* padding-right: 30px; */ background: #099; white-space: nowrap; } </style>

box宽度100%会有问题

  1. li宽度固定

    <template>
    • {{item.name}}
    </template> <script> export default { name: "HelloWorld", data() { return { timer: null, pwidth: 0, left: 0, items: [ { name: "1马dfgdfgs云1马dfgdfgs云1马dfgdfgs云1马dfgdfgs云", active: false }, { name: "2雷dfgd军", active: false }, { name: "3dsfgd张珊", active: false } ] }; },

    mounted() {
    this.setLeft();
    },
    watch: {},
    methods: {
    setLeft() {
    let num = this.items.length * 230;
    this.timer = setInterval(() => {
    this.left--;
    if (-num >= this.left) {
    console.log("this.left", this.left);
    console.log("-num", -num);
    this.left = 0;
    }
    }, 30);
    },
    clearLeft() {
    if (this.timer) clearInterval(this.timer);
    }
    },
    beforeDestroy() {
    if (this.timer) clearInterval(this.timer);
    }
    };
    </script>

    <style scoped> * { margin: 0; padding: 0; } #app { margin-top: 60px; margin-left: 200px; text-align: center; } #box { /* width: 600px; */ height: 50px; overflow: hidden; border: 1px solid #090; } ul { display: inline-block; padding: 0px; margin: 0px; display: flex; /* width: 320px; */ height: 50px; border: 1px solid #f00; } li { width: 200px; padding: 0px; margin: 0px 30px 0px 0px; list-style: none; background: #099; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } </style>
相关推荐
酷酷的阿云2 分钟前
不用ECharts!从0到1徒手撸一个Vue3柱状图
前端·javascript·vue.js
微信:137971205874 分钟前
web端手机录音
前端
齐 飞10 分钟前
MongoDB笔记01-概念与安装
前端·数据库·笔记·后端·mongodb
神仙别闹27 分钟前
基于tensorflow和flask的本地图片库web图片搜索引擎
前端·flask·tensorflow
aPurpleBerry1 小时前
JS常用数组方法 reduce filter find forEach
javascript
GIS程序媛—椰子1 小时前
【Vue 全家桶】7、Vue UI组件库(更新中)
前端·vue.js
DogEgg_0011 小时前
前端八股文(一)HTML 持续更新中。。。
前端·html
ZL不懂前端1 小时前
Content Security Policy (CSP)
前端·javascript·面试
乐闻x2 小时前
ESLint 使用教程(一):从零配置 ESLint
javascript·eslint
木舟10092 小时前
ffmpeg重复回听音频流,时长叠加问题
前端