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>
相关推荐
夏之小星星12 分钟前
el-tree结合checkbox实现数据回显
前端·javascript·vue.js
crazyme_626 分钟前
前端自学入门:HTML 基础详解与学习路线指引
前端·学习·html
撸猫79134 分钟前
HttpSession 的运行原理
前端·后端·cookie·httpsession
亦世凡华、1 小时前
Rollup入门与进阶:为现代Web应用构建超小的打包文件
前端·经验分享·rollup·配置项目·前端分享
琉璃℡初雪1 小时前
vue2/3 中使用 @vue-office/docx 在网页中预览(docx、excel、pdf)文件
vue.js·pdf·excel
Bl_a_ck1 小时前
【React】Craco 简介
开发语言·前端·react.js·typescript·前端框架
为美好的生活献上中指2 小时前
java每日精进 5.11【WebSocket】
java·javascript·css·网络·sql·websocket·网络协议
augenstern4162 小时前
webpack重构优化
前端·webpack·重构
海拥✘2 小时前
CodeBuddy终极测评:中国版Cursor的开发革命(含安装指南+HTML游戏实战)
前端·游戏·html
寧笙(Lycode)3 小时前
React系列——HOC高阶组件的封装与使用
前端·react.js·前端框架