最近個人サイトで作業していて、jQueryScrollTopを使用してコンテンツdivをアニメーション化しています。しかし、私は問題に遭遇しました。
1番目:関係するすべての上部に奇妙なパディングがあります
2番目:スクロールが一貫していません。毎回同じ高さでスクロールするわけではありません。
あなたはここでページを見ることができます:http://mnpwr.dk/v2/index.html
-周りに赤い境界線を追加したので、問題がわかりやすくなります。
jQuery:
jQuery.noConflict();
jQuery(document).ready(function () {
getHash();
});
// Keep track of our current state
currentSection = 1;
function getHash() {
jQuery('.scroll').on('click', function () {
// Get our new state
var gethash = jQuery(this).attr('class').split(' ')[0];
// Calculate the difference, with element height of 500px using formular dest = (newPows - currentPos) * elmHeight
var scrollTop = (gethash - currentSection) * 500
jQuery('#contentDiv').animate({
scrollTop: scrollTop
}, 500);
return false;
});
}