我想复制Facebook时间轴日期选择器/页面滚动器的功能。这可以在Facebook时间表页面的右上角看到。当您选择一年,使用动画效果时,页面会将时间线向下滚动到该特定年份。下面是我一直试图去为我工作的代码:如何创建Facebook时间轴样式日期滚动器?
<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>
我试图做的是刚刚获得寡妇滚动到正确的DIV的第一件事。然后,我想添加一个类似于Facebook的动画效果。
您必须将'window.moveTo()'替换为'window.scrollTo()'。 –
你可以查看这个http://www.technotarek.com/timeliner/timeliner.html –