我的印象是,$('body').offset().top
應返回0
上沒有別的,但顯然它不斷返回8
。我從我的網頁中刪除了所有不必要的代碼,它仍然返回8
。
以下是我有:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
$(document).ready(function() {
console.log($('body').offset().top);
})
</script>
</body>
</html>
這是字面上的在我的代碼的一切。這裏是JSFiddle:http://jsfiddle.net/Lspkx2su/
身體的邊距默認爲8,嘗試將其設置爲0或使用css重置。 – 2014-08-29 07:13:34
重置的替代方法是normalize.css,它保留了有用的設置並使其在不同瀏覽器中保持一致。這有點偏離主題,但值得注意的是:http://necolas.github.io/normalize.css/ – 2014-08-29 07:22:43