使用 jQuery Waypoints 插件的粘性导航栏

发布于 2024-11-01 21:51:25 字数 545 浏览 4 评论 0原文

我已经使用 jQuery Waypoints 插件创建了一个粘性导航,但是当选择一个部分时,我无法让导航选项始终突出显示。

在我的示例中,您将看到菜单项仅在该部分位于范围内时才处于“活动”状态,并且这会根据视口的高度而变化,这是 Waypoints 默认情况下的工作方式:

http://jsfiddle.net/keith/v6vuN/2/ (或全屏版本:http://jsfiddle.net/keith/v6vuN/2/embedded /result/

我希望菜单项始终突出显示,即使该部分不在范围内。

例如,如果我位于“精选”部分并且“联系人”可见,即使浏览器窗口的高度无法滚动到整个部分,我仍然希望突出显示菜单选项。

这有道理吗?我不想只是在各部分之间或页面底部添加大量填充/边距以使其更长。

I've created a sticky nav using the jQuery Waypoints plugin, but I am having trouble getting the nav options to always highlight when a section is chosen.

In my example you'll see that a menu item is only "active" when the section is within the range, and this changes based on the height of the viewport, which is the way Waypoints is supposed to work by default:

http://jsfiddle.net/keith/v6vuN/2/
(or fullscreen version: http://jsfiddle.net/keith/v6vuN/2/embedded/result/)

I'd like the menu items to always highlight, even if the section isn't within range.

For example, if I'm on the "Featured" section and "Contact" is visible, I'd still like the menu option to highlight even if the browser window's height can't scroll to the entire section.

Does that make sense? I'd rather not just add a lot of padding/margin between the sections or at the bottom of the page to make it longer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梨涡 2024-11-08 21:51:25

在这一部分中,将:更改

// Register each section as a waypoint.
$('#main > .section').waypoint({ offset: '0'});

为:

// Register each section as a waypoint.
$('#main > .section').waypoint({ offset: '50%'});

0 偏移量是距屏幕顶部 0 像素,而 50% 将使其在中间点触发。相应地调整,但 50% 应该这样做。

In this part, change:

// Register each section as a waypoint.
$('#main > .section').waypoint({ offset: '0'});

To:

// Register each section as a waypoint.
$('#main > .section').waypoint({ offset: '50%'});

0 offset is 0px from the top of the screen while 50% will make it fire at the halfway point. Adjust accordingly, but 50% should do it.

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