在Safari中移动元素时SVG上的条纹
当我尝试在SVG上移动一个孩子Div时,SVG开始具有怪异的垂直条纹。这仅在Safari上发生(我在iPad,iPhone,Mac,PC上测试了Chrome和Safari)。
要查看错误,请将光标放在图像上,然后向右移动。如果没有出现,请缩短屏幕的宽度。
function App() {
const [delta, setDelta] = useState(0);
const handleTouchMove = (event) => {
let delta = event.touches[0].clientX;
setDelta(delta);
};
const handleMouseMove = (event) => {
let delta = event.clientX + 40;
setDelta(delta);
};
return (
<div
style={{
background: "#5f5fc4",
display: "flex",
justifyContent: "center",
alignItems: "center",
border: "1px solid #413793"
}}
>
<svg
width="500"
height="500"
onTouchMove={handleTouchMove}
onMouseMove={handleMouseMove}
style={{ background: "#283593" }}
>
<g>
<foreignObject x="0" y="0" width="500" height="500">
<picture>
<img
alt=""
width="100%"
src="https://i.imgur.com/h1vMJwO.png"
/>
</picture>
</foreignObject>
</g>
</svg>
<div style={{ width: delta, background: "#001064", color: "white", fontSize: '1.2rem' }}>
Another div here with {delta}px.
</div>
</div>
);
}
src/app.js“ rel =“ nofollow noreferrer”>此特定错误的存储库
此错误绝对是Safari的特定特定的:但是,从个人经验来看,我已经通过其他项目看到了这种行为,浏览器不是一个项目出现错误的问题。但是我找不到解决方案或解释。
我该如何修复它,或者至少为什么会发生?
预先感谢。
When I try to move a child div on top of an SVG, the SVG starts to have weird vertical stripes. This only happens on Safari (I tested on iPad, iPhone, Mac, PC both Chrome and Safari).
To see the bug, position your cursor over the image, and move to the right. If it doesn't appear, please just shorten the width of the screen.
Reproduction of this bug (vercel.app)
GIF Preview - This is how appears
function App() {
const [delta, setDelta] = useState(0);
const handleTouchMove = (event) => {
let delta = event.touches[0].clientX;
setDelta(delta);
};
const handleMouseMove = (event) => {
let delta = event.clientX + 40;
setDelta(delta);
};
return (
<div
style={{
background: "#5f5fc4",
display: "flex",
justifyContent: "center",
alignItems: "center",
border: "1px solid #413793"
}}
>
<svg
width="500"
height="500"
onTouchMove={handleTouchMove}
onMouseMove={handleMouseMove}
style={{ background: "#283593" }}
>
<g>
<foreignObject x="0" y="0" width="500" height="500">
<picture>
<img
alt=""
width="100%"
src="https://i.imgur.com/h1vMJwO.png"
/>
</picture>
</foreignObject>
</g>
</svg>
<div style={{ width: delta, background: "#001064", color: "white", fontSize: '1.2rem' }}>
Another div here with {delta}px.
</div>
</div>
);
}
Repository of this specific bug
This bug is definitely specific to Safari: However, from personal experience, I have seen this behavior through other projects where the browser is not a problem for the bug to appear. But I can't find a solution or an explanation.
How can I fix it, or at least why does it happen?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常有趣的情况。
我有一个修复程序,但我不知道为什么会发生。可能是Safari渲染问题。
Align-Items:Center
从包装器中背景色:#001064;
从Inner Div和adddisplay:flex; Align-Items:Center;
backick-color:#001064;
并添加width:100%
。Very interesting case.
I have a fix, but I don't know why it happen. Probably safari rendering issue.
align-items:center
from wrapperbackground-color:#001064;
from inner div and adddisplay: flex; align-items: center;
background-color:#001064;
and addwidth:100%
.