Das ist also der aktuelle Code, den ich habe
$(document).ready(function() {
$('.abouta').click(function(){
$('html, body').animate({scrollTop:308}, 'slow');
return false;
});
$('.portfolioa').click(function(){
$('html, body').animate({scrollTop:708}, 'slow');
return false;
});
$('.contacta').click(function(){
$('html, body').animate({scrollTop:1108}, 'slow');
return false;
});
});
Wenn Sie auf einen Link klicken, z. 'abouta' scrollt zu diesem bestimmten Abschnitt der Seite. Ich mache lieber ein scrollTo und dann die id eines div, damit ich die scrollTo-Position nicht ständig ändern muss, wenn ich die Polsterung usw. ändere
anstatt
$('html, body').animate({scrollTop:xxx}, 'slow');
benutzen
$('html, body').animate({scrollTop:$('#div_id').position().top}, 'slow');
dadurch wird die absolute oberste Position des ausgewählten Elements als #div_id
zurückgegeben.
versuche dies:
$('html, body').animate({scrollTop:$('#xxx').position().top}, 'slow');
$('#xxx').focus();
Meine Lösung war folgende:
document.getElementById("agent_details").scrollIntoView();