简体   繁体   English

垂直滚动,使用snap / align to div / element / anchor

[英]Vertical scrolling with snap/align to div/element/anchor

I found some lovely websites - http://www.mini.jp/event_campaign/big-point/ , http://www.twenty8twelve.com/ and http://www.scozzese.com - all vertical scrolling, and all using a technique that aligns the 'pages' to the top of the browser when you scroll onto a new 'page' - even if you scroll half way into one. 我发现了一些可爱的网站- http://www.mini.jp/event_campaign/big-point/http://www.twenty8twelve.com/http://www.scozzese.com -所有垂直滚动,以及所有当您滚动到新的“页面”时,使用一种将“页面”对齐到浏览器顶部的技术 - 即使您将一半滚动到一个页面。

Could anyone give me any pointers eg the right terminology/words I could use to search for more info, or a brief intro on the basics behind this technique, or if any jQuery etc plugins exist I can play and learn with? 任何人都可以给我任何指针,例如我可以用来搜索更多信息的正确术语/单词,或者介绍这种技术背后的基础知识,或者如果存在任何jQuery等插件,我可以玩和学习吗?

I did a search of their code but nothing jumped out as how to do it, my Javascript and jQuery are still novice level. 我搜索了他们的代码但没有跳出来如何做到这一点,我的Javascript和jQuery仍然是新手级别。

Javascript Has some native methods like scroll(), scrollTo(), scrollBy() which (with some tricks) you can use to smoothly scroll the page. Javascript有一些本地方法,如scroll(), scrollTo(), scrollBy() ,你可以使用它们(有一些技巧)来平滑地滚动页面。 Together with offsetTop(), offsetLeft() you can achieve effects like on these sites. offsetTop(), offsetLeft()一起,您可以实现这些网站上的效果。

There are also a lot of jQuery Plugins out there (eg like this google hit ) to save you a lot of work with this. 还有很多jQuery插件(例如像谷歌点击这样 )来为你节省大量的工作。

Just search for these Methodnames, this should give you enough hits I guess. 只是搜索这些方法名称,这应该给你足够的命中我猜。

Basic scrolling... 基本滚动...

// Scroll
h = $(window).height();
t = $("mydiv").offset().top + $("mydiv").height();

if(t > h) {
    $(window).scrollTop(t - h);
}

Their scrolling script isn't very smart. 他们的滚动脚本不是很聪明。 If I scroll the webpage down by repeatedly clicking on the down arrow, every time I click, it scrolls back up. 如果我通过反复单击向下箭头向下滚动网页,每次单击时,它都会向上滚动。 So inevitably it doesn't work. 所以不可避免地它不起作用。

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

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