简体   繁体   English

如何将整个可见页面向下滚动到具有平滑效果的锚点(Scriptaculous或jQuery)?

[英]How to scroll whole visible page down to an anchor with a smooth effect (Scriptaculous or jQuery)?

I want to create an navigation with anchors. 我想用锚点创建导航。 By clicking on a navigation link, the whole visible page should scroll down to the clicked anchor. 通过单击导航链接,整个可见页面应向下滚动到单击的锚点。

The most important is the following structure of the page. 最重要的是页面的以下结构。

--------------- (Begin visible browser area)
NAV1 nav2 nav3

content
--------------- (Begin/end visible browser area)
nav1 NAV2 nav3

content
--------------- (Begin/end visible browser area)
nav1 nav2 NAV3

content
--------------- (end visible browser area)

Finally all content is in a single document and the height of the current page (selected by the nav-item) has to be calculated (with a JS Library). 最后,所有内容都在一个文档中,并且必须计算当前页面的高度(由nav-item选择)(使用JS库)。 I prefer PrototypeJS/Scriptaculous and jQuery. 我更喜欢PrototypeJS / Scriptaculous和jQuery。

The scroll effect should be a smooth slide/ effect. 滚动效果应该是平滑的幻灯片/效果。

Chris 克里斯

If you want a jQuery solution, use ScrollTo , and if all you need is anchor-based animations implement the associated LocalScroll plugin. 如果你想要一个jQuery解决方案,使用ScrollTo ,如果你需要的只是基于锚的动画实现相关的LocalScroll插件。

If you want the content panes to take up the entire visible browser area, you can set that dynamically at page load (and on browser resize) with jQuery as well. 如果您希望内容窗格占据整个可见浏览器区域,您可以使用jQuery在页面加载(以及浏览器调整大小)上动态设置。 There's a great explanation of the "height" method here . 还有的“高度”的方法很好的解释在这里

请参阅: Effect.ScrollTo

<a href="javascript:// scroll" onclick="Effect.ScrollTo('element_id', { duration:'.5'})" />link</a>

I think maybe you could use this scroller: http://ruwix.com/simple-javascript-page-scroll-slider-jquery-scrollto-function-label-end It's the shortest I found so far and it's really simple. 我想也许你可以使用这个卷轴: http//ruwix.com/simple-javascript-page-scroll-slider-jquery-scrollto-function-label-end这是我迄今为止发现的最短的,它非常简单。 Unfortunately it scrolls a fix amount of pixels, not to a label but you could use its idea. 不幸的是,它滚动固定数量的像素,而不是标签,但你可以使用它的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM