我想複製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 –