2
I have a code that scrolls the page to the top, but I don’t want it to reach scrollTop = 0. It’s possible that by clicking the button, it just slightly climbs the page up, as if I had keyboard the arrow up the keyboard?
$(document).ready(function(){ $(window).scroll(function(){
if ($(this).scrollTop() > 10) {
$('#scroll').fadeIn();
}
else {
$('#scroll').fadeOut();
}
});
$('#scroll').click(function(){ $('html, body').animate({ scrollTop: 0 }, 600);
return false;
});
});
#scroll {position:fixed; right:10px; bottom:10px; cursor:pointer; width:40px; height:40px; background-color:#D80000; text-indent:-9999px; display:none; border-radius:60px; box-shadow:-1px 3px 7px rgba(0,0,0,.9)}
#scroll span {position:absolute; top:50%; left:50%; margin-left:-10px; margin-top:-17px; height:0; width:0; border:10px solid transparent; border-bottom-color:#fff}
#scroll:hover {background-color:#A80000; opacity:1}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<body>
<p>Role a página para baixo...</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<a href='#' id='scroll' title='Voltar ao Topo'>Topo<span/></a>
</body>
It would not just edit the value called in the function
animate?
$('#scroll').click(function(){ $('html, body').animate({ scrollTop: 50 }, 600);
– Jorge.M