chrome浏览器下后台疯狂报错,火狐下则正常。求大神指点。

来源:5-2 SVG-利用 dy 属性实现波浪文字效果

HakuPretty

2018-05-27 11:35


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>svg</title>

</head>

<body>

<svg width="1200" height="1000" version="1.1" xmlns="http://www.w3.org/2000/svg">

<defs>

<pattern id="grid" width="20" height="20" patternUnits="userSpaceOnUse">

<path d="M0,0H20V20" stroke-width="1" stroke="#f0f0f0" fill="none"/>

</pattern>

</defs>

<rect x="0" y="0" width="1200" height="1000" fill="url(#grid)" stroke="" stroke-width=""/>

<text x="100" y="150" font-size="14px" font-family="Microsoft YaHei">ABCDEFGHIJKLMNOPQRSTUVWXYZ</text>

<path d="M100,0V200M0,100H200" stroke="red" fill="none" transform=translate(0,50) ></path>


</svg>

<script type="text/javascript">

var n = 26;

var x = [];

var y = null;

var  i = n;

var s = 100;

var w = 0.02;

var t = 0.2;

var sintext = document.getElementsByTagName('text')[0];

while(i--) x.push(20);

function arrange(t) {

y = [];

var ly = 0;

var cy;

for(var i=0;i<n;i++){

cy = -1* s * Math.sin(w * i * 20 + t);

y.push(cy- ly);

ly = cy;

}

}

function render() {

sintext.setAttribute("dx",x.join(' '));

sintext.setAttribute("dy",y.join(' '));

}

function frame() {

t += 0.01;

arrange(t);

render();

requestAnimationFrame(frame);

}

frame();

</script>

</body>

</html>

https://img1.mukewang.com/5b0a277700013b9113440515.jpg



写回答 关注

1回答

  • Nice_lq
    2021-04-26 10:33:05

    现在就可以了

走进SVG

SVG是HTML5 中矢量图的标记语言,学习后掌握更多的干货

52643 学习 · 213 问题

查看课程

相似问题