|
|
做个均匀的练习
- <svg version="1.1" width="400" height="400" viewBox="0 0 400 400" >
- </svg>
- <script>
- let idx = 0;
- let svgObj = document.querySelector('svg');
- for(idx = 0 ; idx < 60; idx++) {
- let gidx = parseInt(idx / 20);
- let crObj = document.createElementNS("http://www.w3.org/2000/svg", "circle");
- crObj.setAttribute('cx', 200);
- crObj.setAttribute('cy', 200);
- crObj.setAttribute('r', 7.5);
- crObj.setAttribute('fill', "#" + Math.random().toString(16).substring(2,8));
- let ang = idx < 20 ? idx * 18 : idx < 40 ? (idx - 20) * 18 : (idx - 40) * 18;
- crObj.setAttribute('transform', `rotate(${ang}, 200, 200)`);
-
- let aObj = document.createElementNS("http://www.w3.org/2000/svg", "animate");
- aObj.setAttribute('id', "a"+idx);
- aObj.setAttribute('attributeName', "cy");
- aObj.setAttribute('from', 200);
- aObj.setAttribute('to', 700);
- aObj.setAttribute('dur', "6s");
- let bt = gidx == 0 ? '0;a40.begin+1' : gidx == 1 ? 'a0.begin+1' : 'a20.begin+1';
- aObj.setAttribute('begin', bt);
-
- crObj.appendChild(aObj)
- svgObj.appendChild(crObj);
- }
- </script>
复制代码 |
|