gpt4 book ai didi

javascript - SVG createElementNS 'use' 这可能吗?

转载 作者:行者123 更新时间:2023-11-30 08:01:08 25 4
gpt4 key购买 nike

缩短,我正在使用(使用)来复制正方形(路径)代码被添加到 DOM 然而,只有 1px(调试 chrome)。第六 block 用户不可见!谢谢你! code in: codepen

$(function() {
$('#svg').css('visibility', 'visible');
$('#svg use').css('fill', '#fff');

function addAnim() {
var $first = $('#svg use:not(.anim):first');
$first.attr('class', 'anim').css('fill', '#F15A29');
$first.animate({fill : '#F15A29'}, 500);
setTimeout(function() {
addAnim();
}, 100);
}

function replicar(){
var svg = document.getElementById('svg');
var elemento= document.createElementNS('ttp://www.w3.org/2000/svg', 'use');
elemento.setAttribute('xlink:href', '#shape');
elemento.setAttribute('y', '62');
elemento.setAttribute('x', '124');
elemento.setAttribute('fill', '#3D6EB5');
svg.appendChild(elemento);


addAnim();
replicar();
});

最佳答案

您在这一行中缺少一个“h”:

var elemento= document.createElementNS('http://www.w3.org/2000/svg', 'use');

此外,xlink 属性需要用setAttributeNS 添加。

elemento.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#shape');

关于javascript - SVG createElementNS 'use' 这可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27976179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com