Я пытаюсь программно создать закругленный угол, используя Javascript и SVG.Угол успешно создан, но path
всегда установлен на 0 ширины и 0 высоты.
Если я скопирую созданный строковый элемент и вставлю его в файл, он будет работать без проблем, как показано навторая строка фрагмента.
Почему только программно созданный путь без ширины и высоты?Чего мне не хватает?
var cornerTopLeft = createCorner("top-left");
applyCornerStyles.call(cornerTopLeft, 0, 0, 10);
var body = document.getElementsByTagName("body")[0];
body.appendChild(cornerTopLeft);
function createCorner(cornerPosition) {
var corner = document.createElement("svg");
corner.setAttribute("fill", "red");
corner.setAttribute("style", "width:10px;height:10px;background-color: red;");
corner.setAttribute("viewBox", "0 0 100 100");
corner.setAttribute("xmlns", "http://www.w3.org/2000/svg")
corner.innerHTML = '<path class="" style="background-color: rgba(0, 0, 0, .5);fill: rgba(0, 0, 0, .5);" d="M100 0 ,Q 0 0 0 100, L0 0, Z"></path>';
return corner;
}
function applyCornerStyles(top, left, size) {
this.style.top = top + "px";
this.style.left = left + "px";
this.style.width = size + "px";
this.style.height = size + "px";
this.style.zIndex = "20002";
this.style.position = "absolute";
}
<h3>This svg was created using svg string created programatcally.</h3>
<svg fill="none" viewbox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" style="top: 22px; left: 510px; width: 10px; height: 10px; z-index: 20001; position: absolute;">
<path class="" style="background-color: rgba(0, 0, 0, .5);fill: rgba(0, 0, 0, .5);" d="M100 0 ,Q 0 0 0 100, L0 0, Z"></path>
</svg>
( скрипка )