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>
相关推荐
又尔D.2 小时前
vue3+webOffice合集
vue.js·weboffice
古蓬莱掌管玉米的神6 小时前
vue3语法watch与watchEffect
前端·javascript
林涧泣6 小时前
【Uniapp-Vue3】uni-icons的安装和使用
前端·vue.js·uni-app
雾恋6 小时前
AI导航工具我开源了利用node爬取了几百条数据
前端·开源·github
拉一次撑死狗6 小时前
Vue基础(2)
前端·javascript·vue.js
祯民6 小时前
两年工作之余,我在清华大学出版社出版了一本 AI 应用书籍
前端·aigc
热情仔7 小时前
mock可视化&生成前端代码
前端
m0_748246357 小时前
SpringBoot返回文件让前端下载的几种方式
前端·spring boot·后端
wjs04067 小时前
用css实现一个类似于elementUI中Loading组件有缺口的加载圆环
前端·css·elementui·css实现loading圆环
爱趣五科技7 小时前
无界云剪音频教程:提升视频质感
前端·音视频