Ich habe das Beispiel versucht in einer leeren HTML-Seite auszuprobieren, bei mir funktioniert das leider nicht.
Kann mir wer sagen was denn an dem code falsch ist?
HTML
<!doctype html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<meta charset="utf-8">
<title>Unbenanntes Dokument</title>
<style>#test {
width: 100px;
height: 100px;
position: relative;
top: 1000px;
background: green;
}</style>
<script>
$('#scroll').click(function() {
$('html,body').animate({
scrollTop: $('#test').css('top')
}, 800, function() {
$('html, body').animate({
scrollTop: 0
}, 800);
});
});
</script>
</head>
<body>
<p><button id="scroll">scrollTop()</button></p>
<div id="test"></div>
</body>
</html>
Alles anzeigen