Comment: The function of imitating CSDN Blog returns to the top of the page has only been modified in 2 places: Return speed --> Change it to go back slowly, return to the timing of the icon at the top --> Change it to display as long as it is not on the top. The specific code is as follows. Interested friends can refer to it.
Only 2 places have been modified:, the return speed--> has been changed to go back slowly. (It turned out to be a flash back)
, return to the timing of the icon at the top --> changed to display as long as it is not on the top. (It turns out that it will be displayed after scrolling down by 500px)
Note: JS must be written after HTML;
HTML
<div>
<a href="#" /></a>
</div>
Javascript code
<script type="text/javascript">
$(function(){
var d_top=$('#d-top');
document.onscroll=function(){
var scrTop=(document.body.scrollTop||document.documentElement.scrollTop);
if(scrTop>500){
if(scrTop>0){
d_top.show();
}else{
d_top.hide();
}
}
$('#d-top-a').click(function(){
$("html,body").animate({scrollTop: 0},500);
//scrollTo(0,0);
this.blur();
return false;
});
});
</script>
CSS Style
#d-top {
position: fixed;
float: right;
z-index: 10;
right: 10px;
bottom: 40px;
}
#d-top img {
width: 42px;
opacity: 0.3;
}
img {
border: medium none;
}