简体   繁体   English

单击链接时,将重点放在svg元素上

[英]On clicking link, focus on svg element

I just started working with SVG images and I was wondering if it is possible to create a text link that when on click, it focuses on a specific element. 我刚开始使用SVG图像,我想知道是否可以创建一个文本链接,当单击该链接时,该链接将重点放在特定元素上。

For example, I have a text that is located on the far left of my screen and a circle element that can only be seen if I scroll to the far right. 例如,我的文字位于屏幕的最左侧,而圆形元素只有在滚动至最右侧时才能看到。 And when I click on said text, it would then scroll or jump to that element. 当我单击该文本时,它将滚动或跳转到该元素。

I'm still somewhat a beginner at this, so any help would be greatly appreciated. 我还是这个的初学者,所以任何帮助将不胜感激。

If you want to snap to an element, you can always do the following. 如果要捕捉到元素,则始终可以执行以下操作。

<div id="snap-to-me"></div>

<a href="#snap-to-me">SNAP</a>

Upon clicking the link, the page will try to find an element with that id, and snap to it. 单击链接后,页面将尝试查找具有该ID的元素,并对其进行捕捉。

If you want animated scrolling, I suggest you checkout a library that supports it. 如果要动画滚动,建议您检出支持它的库。 jQuery being an obvious, good choice. jQuery是显而易见的不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM