如何制作一个当用户点击链接时从顶部向下滚动的div?
我想写一些JS,让我能够重现点击链接时该网站所达到的效果:
如果你访问这个链接然后点击页面右上角的小图标之一,你就会看到我想要用js实现的效果。我认为这是某种具有 js 操作的隐藏或重新定位的 div。
非常感谢帮助, 谢谢瑞安。
I would like to write some JS that allows me to recreate the effect this website achieved when you click on the links:
If you visit this link then click one of the small icons in the upper right corner of the page, you will see the desired effect that I want to achieve with js. I assume this is some kind of hidden or repositioned div that has a js action.
Help would be much appreciated,
Thanks Ryan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它并不是真正从顶部滚动,而是使用动画将 div 引入视图。有几个 JS 库可以帮助您完成此任务,而无需您编写自己的库。
研究一下 JQuery 和 Scriptaculous。两者都有很好的例子,你可以看看。
该网站使用 JQuery。
It's not really scrolling from top it is bringing the div into view using animation. There are several JS libraries out there that can help you with this without you writing your own.
Look into JQuery and Scriptaculous. Both have great examples you can look at.
That site uses JQuery.
基本上你所拥有的是一个隐藏的 div,其中包含一些信息并调用了 jQuery 方法 .hide() 。当用户将鼠标悬停在这些链接之一上时,就会使用 jQuery 方法 .show() 调用该 div。他们的版本是通过自定义脚本完成的。
Basically what you have there is a hidden div which contains some information and has had jQuery method .hide() called on it . When the user mouses over one of those links, the div is then called using the jQuery method .show(). Their version is done with custom scripting.
您可以使用 CSS3 过渡来做到这一点:
使用像这样的 div:
请记住,只有 IE10 才会在此处生成幻灯片效果,因为 IE9 及更低版本目前不支持过渡。该按钮只会导致 div 在这些浏览器中“快速”打开和关闭。
You could do this with CSS3 transitions:
With a div like so:
Keep in mind that only IE10 would generate the slide effect here as IE9 and below don't presently support transitions afaik. The button would just cause the div to "snap" open and closed in these browsers.