使用 jQuery 突出显示目的地的滚动效果
我发现了 jQuery 的锚点插件,其演示站点位于 http://www. position-relative.net/creation/anchor/。
我正在网站上开发一个常见问题解答页面,其中问题列表后面跟着答案列表。当用户单击问题时,我可以使用滚动效果向下移动到相应的答案。但我也希望以某种方式突出显示答案,以便用户可以专注于答案。
我想达到这样的效果。另外,如果您知道任何其他插件可以执行此操作,请告诉我。
I found an anchor plugin for jQuery, and its demo site is at http://www.position-relative.net/creation/anchor/.
I am developing a FAQ page on a website where a list of questions are followed by a list of answers. I could use the scroll effect to move down to the corresponding answer when a user click a question. But I also want the answer is highlighted in some ways or others so that a user can get focused on the answer.
I would like to achieve the effect. Also, if you know any other plugin to do this, please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用锚点插件调用时:
您还可以绑定自己的函数来执行突出显示,如下所示:
这要求您具有这种结构:
的外观:
在 CSS 中,您只需定义突出显示部分 jQuery 代码的工作方式是,当您单击锚链接时,它首先删除当前突出显示,然后将突出显示类应用于紧邻链接目标之后的元素。
您可以通过执行某种颜色淡入淡出动画来扩展此功能,如 SO 中所示,但这应该可以帮助您入门。
As you invoke the anchor plugin using:
you could also bind your own function that does the highlighting as so:
This requires that you have this kind of structure:
And in CSS, you just define how you want the highlighted part to look like:
The jQuery code works so that when you click an anchor link, it first removes current highlights and then applies the highlight class to the element immediately after the link target.
You could expand this functionality by doing some kind of color fade animation like here in SO, but this should get you started.
我个人会使用 jquery.scrollTo 来突出显示它非常简单,只需在包含答案的 span/div 上使用 .toggleclass() 即可。
I'd use jquery.scrollTo personally, to highlight it is pretty simple, just use .toggleclass() on the span/div that wraps the answer.