预警信息

当前位置:   article > 正文

vue+Element实现文字列表轮番滚动效果_element内容滚动

element内容滚动
  1. <template> <div style="position: relative;">
  2. <p class="spans"><img src="../../assets/img/block-title-icon.png" alt=""><span class="tit">预警信息</span></p>
  3. <div v-if="!chuxians" ref="message" class="messages">
  4. <div ref="infobord1" class="content-issue">
  5. <p v-if="chuxian" @click="geti(index)" v-bind:class="getInfoClass(item.type)" v-for="(item,index) in messages"
  6. > <span> {{item.info}}</span> <span><span class="icon"><i class="el-icon-arrow-right"></i></span></span> </p>
  7. </div>
  8. <div ref="infobord1" class="content-issue">
  9. <p v-if="chuxian" @click="geti(index)" v-bind:class="getInfoClass(item.type)" v-for="(item,index) in messages"
  10. > <span> {{item.info}}</span> <span><span class="icon"><i class="el-icon-arrow-right"></i></span></span> </p>
  11. </div>
  12. </div>
  13. <div v-else ref="chuxians" class="chuxians">
  14. <i @click="go" class="el-icon-back" style="left:280px;top:30px;position: absolute"></i>
  15. <div class="content-text"> {{nei}} </div>
  16. <div class="foot">
  17. 紧急联系人:周峰 <br/>
  18. 联系人电话:15515554312
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. chuxian: true,
  28. chuxians: false,
  29. nei: "",
  30. messages: [
  31. {
  32. type: "报警",
  33. deviceId: 12,
  34. info: "温度传感器西特Setra STC温度读数异常"
  35. },
  36. {
  37. type: "报警",
  38. deviceId: 12,
  39. info: "西特Setra 230湿/ 湿差压传感器异常"
  40. },
  41. {
  42. type: "警告",
  43. deviceId: 12,
  44. info: "江森VG1000系列电动球阀异常"
  45. },
  46. {
  47. type: "警告",
  48. deviceId: 12,
  49. info: "压力传感器西特Setra 231 型读数异常"
  50. },
  51. {
  52. type: "警告",
  53. deviceId: 12,
  54. info: "传感器西特Setra SRIM2 型温度异常"
  55. },
  56. {
  57. type: "警告",
  58. deviceId: 12,
  59. info: "NS系统温控异常"
  60. },
  61. {
  62. type: "报警",
  63. deviceId: 12,
  64. info: "J651-T智能感温探测器读数异常"
  65. },
  66. {
  67. type: "警告",
  68. deviceId: 12,
  69. info: "机械温控面板 T2000AAC-0C0有问题"
  70. },
  71. { type: "报警", deviceId: 1, info: "监测到有害气体,请尽快疏散" }
  72. ]
  73. };
  74. },
  75. methods: {
  76. go() {
  77. this.chuxian = true;
  78. this.chuxians = false;
  79. },
  80. geti(i) {
  81. this.chuxian = false;
  82. this.chuxians = true;
  83. this.nei = this.messages[i].info;
  84. // this.$refs.chuxians.innerHTML(this.messages[i].info);
  85. console.log(this.messages[i].info);
  86. },
  87. getInfoClass: function(type) {
  88. if (type === "警告") {
  89. return "warn";
  90. } else if (type === "报警") {
  91. return "alert";
  92. } else {
  93. return "info";
  94. }
  95. },
  96. rollText: function() {
  97. var speed = 50;
  98. var that = this;
  99. function Marquee() {
  100. // that.rollContainer.offsetHeight - that.rollContainer.scrollTop <=
  101. // -(that.rollContainer.scrollTop / 2)
  102. if (that.message.scrollTop == 80) {
  103. that.message.scrollTop = 0;
  104. } else {
  105. that.message.scrollTop++;
  106. // console.log(that.message.scrollTop);
  107. // console.log(that.infobord1.offsetTop);
  108. }
  109. }
  110. var MyMar = setInterval(Marquee, speed); //设置定时器
  111. //鼠标移上时清除定时器达到滚动停止的目的
  112. this.message.addEventListener("mouseover", function() {
  113. clearInterval(MyMar);
  114. });
  115. //鼠标移开时重设定时器
  116. this.message.addEventListener("mouseout", function() {
  117. MyMar = setInterval(Marquee, speed);
  118. });
  119. }
  120. },
  121. mounted() {
  122. this.message = this.$refs.message;
  123. this.infobord1 = this.$refs.infobord1;
  124. this.infobord2 = this.$refs.infobord2;
  125. this.rollText();
  126. }
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .chuxians{
  131. width: 305px;
  132. height: 200px;
  133. position: absolute;
  134. background: url("../../assets/img/station-detail-bg.png") center no-repeat;
  135. background-size: 100% 90%;
  136. }
  137. .foot{
  138. margin-left: 20px;
  139. width: 300px;
  140. text-align: left;
  141. position: absolute;
  142. line-height: 20px;
  143. bottom: 10%;
  144. }
  145. .spans{
  146. height: 30px;
  147. vertical-align: middle;
  148. line-height: 30px;
  149. }
  150. .text-info{
  151. max-width: 240px;
  152. text-align: left;
  153. overflow: hidden;
  154. text-overflow: ellipsis;
  155. background: none;
  156. }
  157. .content-text{
  158. float: left;
  159. text-align: left;
  160. padding-top: 100px;
  161. margin-left: 20px;
  162. width: 290px;
  163. text-indent:35px;
  164. line-height: 23px;
  165. }
  166. .content-issue {
  167. width: 88%;
  168. margin: 0 auto;
  169. /*margin-top: 20px;*/
  170. }
  171. .content-issue p {
  172. color: white;
  173. width: 100%;
  174. margin-top: 4px;
  175. // margin: 5px 12px;
  176. font-size: 14px;
  177. cursor: pointer;
  178. display: flex;
  179. justify-content: flex-start;
  180. background: #011d49;
  181. margin-top: 2px;
  182. padding: 6px 6px 6px 0;
  183. // border-radius: 4px;
  184. position: relative;
  185. white-space: nowrap;
  186. position: relative;
  187. }
  188. .content-issue p span:nth-child(1) {
  189. // position: absolute;
  190. // left: 0;
  191. // top: 0;
  192. // height: 12px;
  193. }
  194. .icon {
  195. position: absolute;
  196. right: 10px;
  197. top: 6px;
  198. /*width: 95%;*/
  199. }
  200. .content-issue p:hover {
  201. // color: white;
  202. // margin: 5px 12px;
  203. // font-size: 14px;
  204. // cursor: pointer;
  205. // display: flex;
  206. // justify-content: flex-start;
  207. background: #ff5454;
  208. // margin-top: 2px;
  209. // padding: 6px;
  210. // border-radius: 4px;
  211. // white-space: nowrap;
  212. }
  213. .content-issue span {
  214. color: #fff;
  215. margin-left: 5px;
  216. margin-right: 5px;
  217. }
  218. .content-issue span.alert {
  219. color: red;
  220. background: red;
  221. }
  222. .content-issue span.warn {
  223. color: orange;
  224. background: orange;
  225. }
  226. .content-issue p.warn {
  227. border-left: orange 4px solid;
  228. }
  229. .content-issue p.alert {
  230. border-left: #ff5454 4px solid;
  231. }
  232. .content-issue span.info {
  233. color: #39d6fe;
  234. background: #39d6fe;
  235. }
  236. .messages {
  237. position: relative;
  238. width: 305px;
  239. height: 200px;
  240. margin-top: 10px;
  241. border-bottom: 1px solid #032a69;
  242. border-top: 1px solid #032a6a;
  243. overflow: hidden;
  244. }
  245. </style>

实现的效果

文字列表轮番滚动,鼠标悬停事件,点击消息可查看详情

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/119020?site
推荐阅读
相关标签