html - 我可以通过CSS指定折线的点吗

标签 html css svg polyline points

polyline{
  points: 35,35 40,50 70,50;
}


    
<svg width='80px' height='80px'>
 <rect width='80' height='80' fill='none' stroke='black'></rect>
  <polyline points="35,35 40,50 60,10" fill="none"  stroke="black" stroke-width='2'></polyline>
</svg>
      

请告诉我是否可以通过CSS设置折线

最佳答案

function setPointsOnPoly(pointList, elemId) {
  obj = document.getElementById(elemId);
  obj.setAttribute("points", pointList);
}

function removePoints(elemId) {
  obj = document.getElementById(elemId);
  obj.removeAttribute("points");
}

setPointsOnPoly('35,35 40,50 70,10', 'polyCheck');
<svg width='80px' height='80px'>
 <rect width='80' height='80' fill='none' stroke='black'></rect>
  <polyline id="polyCheck" fill="none"  stroke="black" stroke-width='2'></polyline>
</svg>
<button onclick="setPointsOnPoly('35,35 40,50 70,10', 'polyCheck');">Set Check</button>
<button onclick="removePoints('polyCheck');">Remove Check</button>

我会在 javascript 中执行此操作,这与您在 CSS 端所需的输入非常接近。

如果您想进一步阅读如何通过 CSS 实际完成所有这些操作,我建议您阅读 HERE .

提供的链接基本上使用 jQuery,但这对您来说应该感觉更舒服一些,因为它通过与 CSS 相同的语法访问元素。

关于html - 我可以通过CSS指定折线的点吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51066433/

相关文章:

javascript - 覆盖链接的按钮

html - 使用超链接在复选框 hack 中切换复选框的状态

html - css中定位div,一左一右

html - Chrome 中的 HTML 布局与 Safari 不同

html - 为什么 svg 和 css 屏蔽(clippathing)不起作用

html - SVG 剪辑路径不适用于 div

html - 为嵌套在固定容器内的绝对位置设置 Z-index

javascript - 在需要访问标题中的文本框的窗口中滚动

具有变换的CSS关键帧动画不适用于SVG

html - AngularJS 风格不适用于新环境