jQuery 视口选择器插件失火
我知道这个插件绝对有效 - 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是猜测,但您有 #content-header 的 href,因此请尝试:
好吧,失败了。尝试:
Just a guess, but you have a href of #content-header, so try:
OK, fail there. Try: