During the transform animation, the text begins to shaking, after research, I realized that it depends on container viewport. If the viewport is small, then we can see that the text is shaking, if viewport is big, the text does not start shaking and animation runs smoothly.
Small viewport example:
const groupList = document.querySelectorAll("svg g");
const container = document.querySelector("#container");
const containerViewport = [20,20];
// const containerViewport = [100,100];
container.style.width = `${containerViewport[0]}%`;
container.style.height = `${containerViewport[1]}%`;
// cannot change this
const increaseRatio = 0.1;
const values = [
30, 70, 110
]
for (const [key, node] of groupList.entries()) {
node.setAttribute("transform", `translate(29, ${values[key]})`)
}
setInterval(()=>{
for (const [key, node] of groupList.entries()) {
values[key] = values[key] + increaseRatio;
node.setAttribute("transform", `translate(29, ${values[key]})`)
}
},20)
.tick {
color: #fff;
}
.line {
stroke: #fff;
}
<div style="background: gray;" id="container">
<svg width="100%" height="100%" viewBox="0 0 411 252" xmlns="http://www.w3.org/2000/svg">
<g>
<text x="0" y="-10" style="" class="tick">15</text>
<line x1="0" y1="0" x2="381" y2="0" class="line"></line>
</g>
<g>
<text x="0" y="-10" style="" class="tick">10</text>
<line x1="0" y1="0" x2="381" class="line" y2="0"></line>
</g>
<g>
<text x="0" y="-10" style="" class="tick">5</text>
<line x1="0" y1="0" x2="381" class="line" y2="0"></line>
</g>
</svg>
</div>
Big viewport example:
const groupList = document.querySelectorAll("svg g");
const container = document.querySelector("#container");
// const containerViewport = [20,20];
const containerViewport = [100,100];
container.style.width = `${containerViewport[0]}%`;
container.style.height = `${containerViewport[1]}%`;
// cannot change this
const increaseRatio = 0.1;
const values = [
30, 70, 110
]
for (const [key, node] of groupList.entries()) {
node.setAttribute("transform", `translate(29, ${values[key]})`)
}
setInterval(()=>{
for (const [key, node] of groupList.entries()) {
values[key] = values[key] + increaseRatio;
node.setAttribute("transform", `translate(29, ${values[key]})`)
}
},20)
.tick {
color: #fff;
}
.line {
stroke: #fff;
}
<div style="background: gray;" id="container">
<svg width="100%" height="100%" viewBox="0 0 411 252" xmlns="http://www.w3.org/2000/svg">
<g>
<text x="0" y="-10" style="" class="tick">15</text>
<line x1="0" y1="0" x2="381" y2="0" class="line"></line>
</g>
<g>
<text x="0" y="-10" style="" class="tick">10</text>
<line x1="0" y1="0" x2="381" class="line" y2="0"></line>
</g>
<g>
<text x="0" y="-10" style="" class="tick">5</text>
<line x1="0" y1="0" x2="381" class="line" y2="0"></line>
</g>
</svg>
</div>
I tried to increase svg viewBox, but it does not matter, text still shaking.
Video demonstration: https://youtu.be/d_aIIDfCHB0