• vue通知(滚动)


    1. li宽度不顾定

    1. <template>
    2. <div id="app">
    3. <div id="box" @mouseover="clearLeft" @mouseleave="setLeft">
    4. <ul :style="{ transform: 'translateX(' + left + 'px)' }" ref="cmdlist">
    5. <li v-for="(item,index) in items" :key="index">{{item.name}}</li>
    6. </ul>
    7. </div>
    8. </div>
    9. </template>
    10. <script>
    11. export default {
    12. name: "HelloWorld",
    13. data() {
    14. return {
    15. timer: null,
    16. pwidth: 0,
    17. left: 0,
    18. items: [
    19. {
    20. name: "1马dfgdfgs云1马dfgdfgs云1马dfgdfgs云1马dfgdfgs云",
    21. active: false
    22. },
    23. {
    24. name: "2雷dfgd军",
    25. active: false
    26. },
    27. {
    28. name: "3dsfgd张珊",
    29. active: false
    30. }
    31. ]
    32. };
    33. },
    34. mounted() {
    35. this.setLeft();
    36. },
    37. watch: {},
    38. methods: {
    39. setLeft() {
    40. let element = this.$refs.cmdlist;
    41. this.pwidth = document.defaultView
    42. .getComputedStyle(element, "")
    43. .width.split("px");
    44. this.timer = setInterval(() => {
    45. this.left--;
    46. let num = parseInt(this.pwidth[0]);
    47. if (-num >= this.left) {
    48. console.log("this.left", this.left);
    49. console.log("-num", -num);
    50. this.left = 0;
    51. }
    52. }, 30);
    53. },
    54. clearLeft() {
    55. if (this.timer) clearInterval(this.timer);
    56. }
    57. },
    58. beforeDestroy() {
    59. if (this.timer) clearInterval(this.timer);
    60. }
    61. };
    62. </script>
    63. <style scoped>
    64. * {
    65. margin: 0;
    66. padding: 0;
    67. }
    68. #app {
    69. margin-top: 60px;
    70. margin-left: 200px;
    71. text-align: center;
    72. }
    73. #box {
    74. width: 600px;
    75. height: 50px;
    76. overflow: hidden;
    77. border: 1px solid #090;
    78. }
    79. ul {
    80. padding: 0px;
    81. margin: 0px;
    82. display: flex;
    83. /* width: 320px; */
    84. height: 50px;
    85. border: 1px solid #f00;
    86. }
    87. li {
    88. list-style: none;
    89. padding: 0px;
    90. margin: 0px;
    91. /* padding-right: 30px; */
    92. background: #099;
    93. white-space: nowrap;
    94. }
    95. </style>

    box宽度100%会有问题

    2. li宽度固定

    1. <template>
    2. <div class="notice">
    3. <div class="left">
    4. <img src="../../../assets/layout/notice.png" alt />
    5. 最新公告:
    6. </div>
    7. <div class="center" @mouseleave="setTimer" @mouseover="clearTimer">
    8. <ul :style="{ transform: 'translateX(' + left + 'px)' }" ref="cmdlist">
    9. <li v-for="(item,index) in items" :key="index">{{item.name}}</li>
    10. </ul>
    11. </div>
    12. <div class="right">2023-10-23 084950</div>
    13. </div>
    14. </template>
    15. <script>
    16. export default {
    17. data() {
    18. return {
    19. timer: null,
    20. left: 0,
    21. items: [
    22. {
    23. name:
    24. "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
    25. active: false
    26. },
    27. {
    28. name: "222222222222222222222222222222222222222222222222222222222",
    29. active: false
    30. },
    31. {
    32. name: "3333333333333333333333333",
    33. active: false
    34. }
    35. ]
    36. };
    37. },
    38. computed: {
    39. // ...mapGetters(["ndid", "eid", "ichnoUrl"])
    40. },
    41. methods: {
    42. setTimer() {
    43. let num = (this.items.length - 1) * 1600;
    44. this.timer = setInterval(() => {
    45. this.left--;
    46. if (-num >= this.left) {
    47. this.left = 1600;
    48. }
    49. }, 10);
    50. },
    51. clearTimer() {
    52. if (this.timer) clearInterval(this.timer);
    53. }
    54. },
    55. mounted() {
    56. this.setTimer();
    57. },
    58. components: {},
    59. watch: {},
    60. beforeDestroy() {
    61. if (this.timer) clearInterval(this.timer);
    62. }
    63. };
    64. </script>
    65. <style rel="stylesheet/scss" lang="scss" scoped>
    66. .notice {
    67. display: flex;
    68. height: 40px;
    69. line-height: 40px;
    70. background: rgba(3, 110, 184, 0.41);
    71. // margin-top: 110px;
    72. font-size: 14px;
    73. z-index: 9999;
    74. background: #090;
    75. .left {
    76. width: 130px;
    77. color: rgb(2, 230, 255);
    78. img {
    79. width: 14px;
    80. margin: 12px 5px 0px 30px;
    81. float: left;
    82. }
    83. }
    84. .center {
    85. width: 1600px;
    86. overflow: hidden;
    87. cursor: pointer;
    88. ul {
    89. width: 4800px;
    90. padding: 0px;
    91. margin: 0px;
    92. }
    93. li {
    94. float: left;
    95. width: 1600px;
    96. padding: 0px;
    97. margin: 0px;
    98. list-style: none;
    99. // background: #099;
    100. white-space: nowrap;
    101. text-overflow: ellipsis;
    102. overflow: hidden;
    103. color: #fff;
    104. }
    105. }
    106. .right {
    107. width: 190px;
    108. color: rgb(2, 230, 255);
    109. }
    110. }
    111. </style>

    li的宽度是1600px,图片可以注释掉,设计稿宽度是1920px

  • 相关阅读:
    总结:从实模式到保护模式的流程和相关寄存器,相关数据结构之间的联系
    layui表格删除最后一页数据时,不会刷新到前一页问题:
    EVA: Visual Representation Fantasies from BAAI
    最短路径专题5 最短路径
    项目规划得心应手:Plane 助你打造高效能团队 | 开源日报 No.48
    Python中2种常用数据可视化库:Bokeh和Altair
    大数据课程K21——Spark的SparkSQL基础语法
    prometheus+process_exporter进程监控
    私有化轻量级持续集成部署方案--07-私有NPM仓库-Verdaccio
    项目基本搭建流程
  • 原文地址:https://blog.csdn.net/weixin_44042792/article/details/133948846