查找 SVG 元素在视口中是否可见
假设我有一些如下所示的 SVG。 #canvas
将应用一些转换:
<svg id="viewport" x="0" y="0" width="100%" height="100%">
<g id="canvas" transform="scale(0.17)">
<image class="imageTile" x="0" y="0" width="256" height="256"/>
<image class="imageTile" x="256" y="0" width="256" height="256"/>
<image class="imageTile" x="0" y="256" width="256" height="256"/>
<image class="imageTile" x="256" y="256" width="256" height="256"/>
</g>
</svg>
#canvas
将是可拖动的,因此当我将 .imageTile
拖动到视图中时,我将触发下载。
var tiles = Y.all(".imageTile");
for (var i = 0; i < tiles.size(); i++) {
if (the tile is visible - ??) {
// set its xlink:href attribute
}
}
我知道 getScreenCTM() 会给我一个 SVGMatrix 对象,但我不知道如何使用它来计算交集。我还知道 SVGElement.getIntersectionList()
方法,但它似乎存在一些浏览器兼容性问题。有更好的办法吗?
Say I have some SVG that looks like the following. #canvas
will have some transforms applied:
<svg id="viewport" x="0" y="0" width="100%" height="100%">
<g id="canvas" transform="scale(0.17)">
<image class="imageTile" x="0" y="0" width="256" height="256"/>
<image class="imageTile" x="256" y="0" width="256" height="256"/>
<image class="imageTile" x="0" y="256" width="256" height="256"/>
<image class="imageTile" x="256" y="256" width="256" height="256"/>
</g>
</svg>
#canvas
will be draggable, so when I drag a .imageTile
into view, I will fire off a download.
var tiles = Y.all(".imageTile");
for (var i = 0; i < tiles.size(); i++) {
if (the tile is visible - ??) {
// set its xlink:href attribute
}
}
I know that getScreenCTM()
will get me an SVGMatrix object, but I don't know how to use that to calculate the intersection. I'm also aware of the SVGElement.getIntersectionList()
method, but it seems to have some browser compatibility issues. Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 先生的帮助下B. Campin的SVG Open论文,我弄清楚了:
With the help of Mr. B. Campin's SVG Open paper, I figured it out:
viewportElement api
如果不显示 svg,viewPortElement api 将返回 null
viewportElement api
viewPortElement api will return null if svg is not displayed