Jquery Animated Back to Top
-
07-11-2019 - |
質問
I'm currently trying to make a button which will take the user back to the top of the page, but animated. Making the page scroll back up to the top when the button is clicked. I did a search on here and found this..
And I have attempted to make a JSfiddle of this using the following...
CSS
html {
margin:0;
padding:0;
height:2000px;
}
body {
height:2000px;
}
#blue-box {
position:fixed;
width:100px;
height:70px;
margin-left:0px;
margin-top:50px;
background-color:blue;
}
#blue-box h1{
font-family:Constantia;
font-size:20px;
text-align:center;
margin-top:5px;
color:#FFFFFF;
}
HTML
<div id="blue-box">
<h1>Back To Top</h1>
</div>
JavaScript
$(document).ready(function() {
var away = false;
$('#blue-box').click(function() {
$("html, body").animate({scrollTop: 0}, 500);
});
Unfortunately, this doesn't seem to work and I'm wondering whether I have missed something out or done something obviously wrong?
正しい解決策はありません
所属していません StackOverflow