jQuery 视口选择器插件失火

发布于 2024-11-07 05:23:13 字数 1006 浏览 5 评论 0原文

我知道这个插件绝对有效 - http://www.appelsiini.net/projects/viewport ,由于这个 jQuery for Designers 教程 - http:// /jqueryfordesigners.com/scroll-linked-navigation/

您可以在这里看到我的问题:http ://www.jaygeorge.co.uk/gwennan-sage

我想在“联系人”div 处于视图中时触发,但此代码不起作用:

$(window).scroll(function () {
  if ($("#contact-header:in-viewport")) {
     $('nav').css('background-color','red');
  }
});

我也尝试过一些不可行的方法甚至不在页面上,例如

它一直在触发,就好像 #contact-header div 始终处于焦点一样。 但是,您会看到该插件在导航上成功运行,并根据您所在页面的哪个部分显示不同的突出显示。

有什么明显的我做错了吗?

我什至尝试过

$(window).scroll(function () {
    if ($("h6:in-viewport")) {
      $('nav').css('background-color','red');
    }
});

......这仍然突出显示导航红色,即使页面上没有 h6!

非常感谢,

杰伊

I know that this plugin definitely works - http://www.appelsiini.net/projects/viewport, I've already used it successfully on my project in progress thanks to this jQuery for Designers tutorial - http://jqueryfordesigners.com/scroll-linked-navigation/

You can see my problem here: http://www.jaygeorge.co.uk/gwennan-sage

I'd like to have a trigger for when the Contact div is in view, but this code is not working:

$(window).scroll(function () {
  if ($("#contact-header:in-viewport")) {
     $('nav').css('background-color','red');
  }
});

I've also tried something that isn't even on the page e.g.

It's firing off all the time, as though the #contact-header div is always in focus.
However you'll see this plugin successfully works on the navigation, with different highlights depending on which part of the page you're on.

Is there something obvious I'm doing wrong?

I've even tried

$(window).scroll(function () {
    if ($("h6:in-viewport")) {
      $('nav').css('background-color','red');
    }
});

...this is still highlighting the nav red, even though there are no h6s on the page!

Thanks very much,

Jay

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

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

发布评论

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

评论(1

情话墙 2024-11-14 05:23:13

只是猜测,但您有 #content-header 的 href,因此请尝试:

$(window).scroll(function () {
if ($("div#contact-header:in-viewport")) {
 $('nav').css('background-color','red');
}
});

好吧,失败了。尝试:

$(window).scroll(function () {
$("div#contact-header:in-viewport").each(function() {
 $('nav').css('background-color','red');
});
});

Just a guess, but you have a href of #content-header, so try:

$(window).scroll(function () {
if ($("div#contact-header:in-viewport")) {
 $('nav').css('background-color','red');
}
});

OK, fail there. Try:

$(window).scroll(function () {
$("div#contact-header:in-viewport").each(function() {
 $('nav').css('background-color','red');
});
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文