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>
相关推荐
谢尔登几秒前
Webpack 和 Vite 的区别
前端·webpack·node.js
谢尔登几秒前
【Webpack】Tree Shaking
前端·webpack·node.js
过期的H2O217 分钟前
【H2O2|全栈】关于CSS(4)CSS基础(四)
前端·css
纳尼亚awsl30 分钟前
无限滚动组件封装(vue+vant)
前端·javascript·vue.js
八了个戒35 分钟前
【TypeScript入坑】TypeScript 的复杂类型「Interface 接口、class类、Enum枚举、Generics泛型、类型断言」
开发语言·前端·javascript·面试·typescript
西瓜本瓜@37 分钟前
React + React Image支持图像的各种转换,如圆形、模糊等效果吗?
前端·react.js·前端框架
黄毛火烧雪下39 分钟前
React 的 useEffect 钩子,执行一些异步操作来加载基本信息
前端·chrome·react.js
蓝莓味柯基44 分钟前
React——点击事件函数调用问题
前端·javascript·react.js
资深前端之路1 小时前
react jsx
前端·react.js·前端框架
cc蒲公英1 小时前
vue2中使用vue-office库预览pdf /docx/excel文件
前端·vue.js