使用 jQuery 突出显示目的地的滚动效果

发布于 2024-08-16 18:22:07 字数 463 浏览 2 评论 0原文

我发现了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧话新听 2024-08-23 18:22:07

当您使用锚点插件调用时:

$(document).ready(function() {
    $("a.anchorLink").anchorAnimate()
});

您还可以绑定自己的函数来执行突出显示,如下所示:

$(document).ready(function() {
    $("a.anchorLink").anchorAnimate().click(function() {
        $('.highlight').removeClass('highlight');
        $('a[name='+$(this).attr('href').substring(1)+']').next().addClass('highlight');
    });
});

这要求您具有这种结构:

<a href="#foobar" class="anchorLink">Anchor link</a>

...

<a name="foobar"></a>
<div>The content you want to highlight</div>

的外观:

.highlight {
    background: #ffc;
}

在 CSS 中,您只需定义突出显示部分 jQuery 代码的工作方式是,当您单击锚链接时,它首先删除当前突出显示,然后将突出显示类应用于紧邻链接目标之后的元素。

您可以通过执行某种颜色淡入淡出动画来扩展此功能,如 SO 中所示,但这应该可以帮助您入门。

As you invoke the anchor plugin using:

$(document).ready(function() {
    $("a.anchorLink").anchorAnimate()
});

you could also bind your own function that does the highlighting as so:

$(document).ready(function() {
    $("a.anchorLink").anchorAnimate().click(function() {
        $('.highlight').removeClass('highlight');
        $('a[name='+$(this).attr('href').substring(1)+']').next().addClass('highlight');
    });
});

This requires that you have this kind of structure:

<a href="#foobar" class="anchorLink">Anchor link</a>

...

<a name="foobar"></a>
<div>The content you want to highlight</div>

And in CSS, you just define how you want the highlighted part to look like:

.highlight {
    background: #ffc;
}

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.

尬尬 2024-08-23 18:22:07

我个人会使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文