1
변수 펠릿 (원 svg)을 pelClass 클래스에 할당하려고합니다. 어떤 이유로 그것은 배정되지 않고 많은 문제를 야기하고 있습니다. 도와주세요!SVG 요소에 클래스를 할당하는 방법
function positionPellet()
{
constantCount = 1;
while(pelletCount < constantCount*3)
{
var pellet = document.createElementNS(xmlns, 'circle');
pellet.setAttribute('cx', Math.random() * window.innerWidth);
pellet.setAttribute('cy', Math.random() * window.innerHeight);
pellet.setAttribute('r' , 10);
pellet.className = "pelClass"; //Pellet Class Adding
pelletCount++;
pelletList = new Array(pelletCount);
pelletList.push(pellet);
svg.appendChild(pellet);
}
}
pelletList = 새 Array (HTML와 동일하게 작동)의 setAttribute (pelletCount)를 사용할 수 있습니다; ? 정말로 새로운 배열을 만들고 싶습니까? 어쩌면이 문은 루프 앞에 실행되어야합니다. – user2182349
'pellet.class = "pelClass";'시도 했습니까? 왜 당신의 문제를 "클래스에 한개의 변수를 할당하려고"한다고 묘사 했습니까? SVG 요소에 클래스를 할당하려고하면 안됩니까? –
제대로 pelletCount, xmlns 및 svg 값을 할당하면 코드가 제대로 작동합니다. 뭐가 문제 야? – Deep