CSS折线

清疚 2023-08-17 15:39 179阅读 0赞
  1. // 写在vue项目中的
  2. <template>
  3. <div id="app">
  4. <div class="list">
  5. <div class="item" v-for="(item,index) in list" :key="index">
  6. <ul :class="`dot_box dot_box${nn + 1}`" v-for="(mm, nn) in [1,2,3]" :key="nn">
  7. <li :class="`dot dot${nn + 1}`">
  8. <p class="location"></p>
  9. </li>
  10. </ul>
  11. </div>
  12. <div class="line_box">
  13. <p :class="`line line${index}`" v-for="(item,index) in list" :key="item.id"></p>
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'App',
  21. data() {
  22. return {
  23. list: [
  24. {status: 1, id: 2003, location:{}},
  25. {status: 1, id: 211, location:{}},
  26. {status: 0, id: 13, location:{}},
  27. {status: 1, id: 203, location:{}},
  28. {status: 2, id: 22, location:{}},
  29. {status: 0, id: 23, location:{}},
  30. {status: 1, id: 213, location:{}},
  31. {status: 0, id: 273, location:{}},
  32. {status: 2, id: 234, location:{}},
  33. {status: 0, id: 324, location:{}},
  34. {status: 1, id: 45, location:{}},
  35. {status: 0, id: 485, location:{}},
  36. {status: 2, id: 15, location:{}},
  37. {status: 0, id: 105, location:{}},
  38. {status: 1, id: 1105, location:{}},
  39. ]
  40. }
  41. },
  42. created() {
  43. let vm = this;
  44. },
  45. mounted () {
  46. let vm = this;
  47. vm.renderLine();
  48. window.onresize = function () {
  49. vm.renderLine();
  50. }
  51. },
  52. components: {
  53. },
  54. methods: {
  55. renderLine() {
  56. let vm = this;
  57. let dot = document.getElementsByClassName('dot');
  58. let hight = dot[0].offsetHeight;
  59. let width = dot[0].offsetWidth;
  60. vm.list.forEach((m, n) => {
  61. let location = {};
  62. location.x = (m.status * width) + (0.5 * width) + m.status + 1;
  63. location.y = (n * hight) + (0.5 * hight) + n + 1;
  64. m.location = location;
  65. if(n != 0 ) {
  66. let css = vm.lineStyle(vm.list[n-1].location.x, vm.list[n-1].location.y, vm.list[n].location.x,vm.list[n].location.y);
  67. $(`.line${n - 1}`).attr('style',css);
  68. }
  69. })
  70. },
  71. lineStyle (x1, y1, x2, y2, lineWidth = 1, color = '#666'){
  72. let rectX = x1 < x2 ? x1 : x2;
  73. let rectY = y1 < y2 ? y1 : y2;
  74. let rectWidth = Math.abs(x1 - x2);
  75. let rectHeight = Math.abs(y1 - y2);
  76. //弦长
  77. let stringWidth = Math.ceil(Math.sqrt((rectWidth * rectWidth) + (rectHeight * rectHeight)));
  78. let xPad = (rectWidth - stringWidth) / 2;
  79. let yPad = (rectHeight - lineWidth) / 2;
  80. let radNum = Math.atan2((y1 - y2), (x1 - x2));
  81. return `
  82. position: absolute;
  83. width: ${ stringWidth }px;
  84. height: ${ lineWidth }px;
  85. background-color: ${ color };
  86. transform: translate(${ rectX + xPad }px, ${ rectY + yPad }px) rotate(${ radNum }rad);`;
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss">
  92. html,body {
  93. width: 100%;
  94. height: 100%;
  95. }
  96. ol,li {
  97. list-style: none;
  98. }
  99. * {
  100. margin: 0;
  101. padding: 0;
  102. }
  103. #app {
  104. position: relative;
  105. width: 100%;
  106. }
  107. .line_box {
  108. width: 300px;
  109. height: 700px;
  110. // border: 1px solid green;
  111. position: absolute;
  112. top: 0;
  113. left: 0;
  114. z-index: 2;
  115. }
  116. .list {
  117. border: 1px solid green;
  118. width: 50%;
  119. .item {
  120. display: flex;
  121. .dot {
  122. width: 10vw;
  123. height: 50px;
  124. border: 1px solid pink;
  125. box-sizing: border-box;
  126. position: relative;
  127. .location {
  128. position: absolute;
  129. width: 10px;
  130. height: 10px;
  131. border-radius: 100%;
  132. top: 0;
  133. left: 0;
  134. right: 0;
  135. bottom: 0;
  136. margin: auto;
  137. z-index: 10;
  138. background: green;
  139. }
  140. }
  141. }
  142. .line {
  143. position: absolute;
  144. }
  145. }
  146. </style>

 效果↓

1202322-20190827182328785-1504425790.png

感谢我牛气轰轰的老大实现了关键部分(划折线函数)

转载于:https://www.cnblogs.com/LLLLily/p/11420049.html

发表评论

表情:
评论列表 (有 0 条评论,179人围观)

还没有评论,来说两句吧...

相关阅读

    相关 折线分割平面

    Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成

    相关 java折线分割平面

    Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成

    相关 折线分割平面

    / 这里我给大家推导以下递推公式的推导步骤: 上面看到了两条折线 和三条折线的画法, 我们先来考虑以下两条折线的画法,同样是两条折线为什么