天天看點

id錨點定位并加上偏移量的

通常錨點定位我們用

location.href = "#elementid";

但當有固定的header時,有可呢會被header覆寫。

解決方法:

頁面将滑動至指定元素id處

$("a").click(function(){
	var index = $("a").index(this);
	$("html,body").animate({scrollTop:$("#elementid" + index).offset().top-105},200)
	return false;
});
           

200為速度

在offset.top上加減适當的數目即可。