我正在尝试创建一条线从窗口的一侧绘制到另一侧。使用JavaScript我希望它在某个时刻。我想检测窗口大小和导航栏高度。我遇到的问题是线路没有显示。使用javascript在svg标签内编辑线条标签
这是我的JavaScript和HTML代码:
<script>
function createLineScreenWidth() {
var elem = getElementsByTagName("svg")[0];
var line = getElementsByTagName("line")[0];
var y_pos = getElementByID("navbar").height;
elem.style.height = "10";
elem.style.width = screen.width;
line.style.stroke = rgb(188, 204, 229);
line.x2 = screen.width;
line.y1 = line.y2 = y_pos;
}
</script>
<div class="navbar" id="navbar">
<nav>
<a href="/contact/"><div class="pageIcon">CONTACT</div></a>
<a href="/products/"><div class="pageIcon">PRODUCTS</div></a>
<a><div class="pageIcon onpageIconChange">ABOUT</div></a>
</nav>
</div>
<svg onload="createLineScreenWidth()">
<line x1="0" style="stroke-width: 2;" />
</svg>
首先什么,除去一些误差存在document.getElementsById有的标记名 第二个没有RGB功能在双引号代替保鲜膜“RGB (0,0,0)“ – owaishanif786