如何使 Viewport(jQuery 插件)在非浏览器窗口的容器上工作?
首先,请原谅我的英语不好......
我设法将问题纳入主题,但这里又更详细了。 我开始使用 jQuery 插件,它添加了一些选择器,例如 :in-viewport、:below-the-fold 等。 这一切都很好,但不幸的是它只将浏览器窗口作为视口。有没有办法修改它来告诉我当元素进入带有溢出:隐藏的div的视口时。 ?
这是插件主页的链接:http://www.appelsiini.net/projects/viewport
请...帮忙!
编辑:提供确切案例的链接:http://mewe.wworks.pl/ 问题在于底部的菜单和滚动条,当 id='life' 的元素滚动到视口中时,它会在相应的菜单项上抛出一个活动类。这是可行的,但它会在 div#life 滚动到浏览器窗口中时立即执行,而不是 div 本身。
希望这是有道理的..
EDIT2:
最终目标是当 #life 穿过 jspPane 的一半时,在 life 'li' 标签上设置 Active 类。现在,只要 #life 进入浏览器窗口(虽然它仍在 jspPane 下方,页脚下方的某处),它就会获取该类。
我在第一篇文章中添加了更多文本,并将文章背景更改为红色,以便更容易阅读发现一切......我想我总体上搞砸了整个代码,因为它现在表现得很奇怪。我花了几个小时试图解决这个问题,但没有运气...
尽管看到这段代码最终工作会让我很高兴,但一个能提供相同效果的好的替代方案也很棒...谢谢进步!
First of all, excuse my bad english...
I managed to fit the question in the topic, but here it goes again in more detail.
I started using a jQuery plugin, that adds a few selectors like :in-viewport, :below-the-fold, etc.
It all works great, but unfortunatelly it only takes the browser window as a viewport. Is there any way to modify it to tell me when an element enters the viewport of a div with overflow: hidden. ?
Heres a link to the plugins main page: http://www.appelsiini.net/projects/viewport
Please... help!
EDIT: Providing a link to the exact case: http://mewe.wworks.pl/
The issue is with the menu and scroller at the bottom, when an element with id='life' scrolls into the viewport it throws an active class on a corresponding menu item. that works, but it does it as soon as the div#life scrolls into the browser window, not the div itself.
Hope that makes sense..
EDIT2:
The final goal is to set the Active class on the life 'li' tag when #life goes half the way up through the jspPane. right now it gets the class as soon as #life enters the browser window (while its still below jspPane, somewhere under the footer)
I added some more text to the first article, and changed articles backgrounds to red to make it a bit easier to spot everything.. I think i messed up the whole code in general couse its acting real weird right now. Ive spent hours trying to sort this out with no luck...
As much as it would make me a happy person to see this code work in the end, a good alternative that gives the same effect would be great aswell... Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我开始自己搞乱它,然后我想出了一个非常简单的代码,可以满足我的需要。我将其放在下面,以防其他人需要类似的东西:
有些值是硬编码在那里的,这并不理想,但这是一种快速的方法。
另外,这段代码非常有用(位于: http://api.jquery.com/位置/#comment-42458111)
};
希望有人会觉得这很有用:)
I started messing around with it a little bit on my own, and i came up with a pretty simple code that does what i needed. Ill put it up below in case anyone else needs something like that:
Some values are hardcoded in there, which isnt ideal, but it was the quick way to go.
Also this bit of code was quite helpful (found at: http://api.jquery.com/position/#comment-42458111)
};
Hope someone will find this usefull :)
我不熟悉该插件,但请尝试
$("#myDiv:in-viewport")
。请务必为您想要的 div 指定id="myDiv"
I'm not familiar with the plugin but try
$("#myDiv:in-viewport")
. Be sure to give the div you want anid="myDiv"