滚动到展开的 DIV 问题和展开框中的链接
我正在为我的新投资组合网站编写代码,并使用砖石来扩展网格布局。
我在使其滚动到展开的 DIV 的代码方面遇到问题。它并不总是滚动到 div .expanded 的上部...这是一个示例:
尝试单击框 1,然后单击框 5。您会注意到页面滚动到框 5 下面的一半。我花了几个小时才让滚动到展开的框正常工作,我jquery 并不是那么好,所以我们将非常感谢您的帮助。 :)
另一件事是,如果您展开框 1 并单击链接,框 1 就会关闭。
我从
I'm working on the code for my new portfolio site and I'm using masonry for the expanding grid layout.
I'm having problems with the code that makes it scroll to the expanded DIV. It doesn't always scroll to the upper part of the div .expanded... Here's a sample:
Try to click box 1 and then box 5. You'll notice that the page scrolls to half-way below box 5. It took me hours to get the scroll-to expanded box working, I'm not really that good in jquery, so help will really be appreciated. :)
Another thing, if you expand box 1 and click on the link, box 1 closes.
I got the sample html/css code from this thread by the way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为
scrollTo
函数在动画完成之前被调用。出于这个原因,jQueryanimate
函数有一个回调(您实际上已经在使用它了)。我刚刚意识到你有其他动画同时进行,所以这不能完全工作。也许 jQuery Effects 文档中的内容可以帮助您 - 特别是 队列/出队部分。
This is because the
scrollTo
function is being called before the animation is finished. The jQueryanimate
function has a callback just for this reason (you are actually already using it).I just realized that you have other animations going on at the same time, so this won't work completely. Maybe Something on the jQuery Effects documentation can help you - specifically the queue/dequeue parts.
使用队列功能几乎可以工作。但是,当另一个盒子展开时,之前展开的盒子将不会恢复/关闭。我将此代码用于此页面:
如果您注意到“next() " 函数已被注释。如果我取消注释“next()”函数,先前展开的框将关闭,但页面不会正确滚动到展开的框。它再滚动大约 100px。
It's almost working using the queue function. However, when another box expands, the previously expanded box won't restore/close. I'm using this code for this page:
If you notice the "next()" function is commented. If I uncomment the "next()" function, the previously expanded box closes but the page won't scroll correctly to the expanded box. It scrolls about 100px more.