[英]How to create a Facebook timeline style date scroller?
I'm trying to replicate the functionality of the Facebook timeline date selector/page scroller. 我正在尝试复制Facebook时间轴日期选择器/页面滚动器的功能。 This can be seen in the top right hand corner of a Facebook timeline page. 这可以在Facebook时间线页面的右上角看到。 When you select a year, using an animated affect, the page scrolls down the timeline to that specific year. 当您使用动画效果选择年份时,页面会向下滚动时间轴到该特定年份。 Here's the code that I've been trying to get to work for me: 这是我一直试图为我工作的代码:
<script type="text/javascript">
$(document).ready(function(){
$("ul a").click(function(event){
if($(this).hasClass("fourthlink")){
// get the coordinates of the fourth div
var offset = $("#sect4").offset();
// alert the y coordinate; I'm getting the right coordinate: 1062
alert(offset.top);
// Here's where I'm trying to move the page to the right spot
window.moveTo(offset.left,offset.top);
// I've also tired window.scrollTo(offset.left,offset.top);
}
})
});
</script>
The first thing I'm trying to do is just get the widow to scroll to the right div. 我要做的第一件事就是让寡妇滚动到正确的div。 Then, I would like to add an animation affect similar to Facebook's. 然后,我想添加一个类似于Facebook的动画效果。
Please correct your code to: 请更正您的代码以:
$(document).ready(function(){
$("ul a").click(function(event){
if($(this).hasClass("fourthlink")){
// get the coordinates of the fourth div
var offset = $("#sect4").offset();
// alert the y coordinate; I'm getting the right coordinate: 1062
alert(offset.top);
// Here's where I'm trying to move the page to the right spot
window.scrollTo(offset.left,offset.top);
// I've also tired window.scorllTo(offset.left,offset.top);
}
})
});
You have to replace: window.moveTo()
to window.scrollTo()
. 您必须替换: window.moveTo()
到window.scrollTo()
。 Or if that doesn't work, try this: 或者,如果这不起作用,请尝试以下操作:
$("html, body").animate({
top: offset.top,
left: offset.left
});
经过更多研究并使用了一些不同的搜索词后,我偶然发现了一个可以解决我的问题的简单插件 ,因此我想与大家分享一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.