页面添加置顶按钮

页面添加置顶按钮,当页面滚动到一定高度时,出现置顶按钮:

添加css样式:
*-----------置顶按钮-----------*/  
.to_top_btn{  
    width:76px;  
    height:54px;  
    background:url(../images/to-top.png);  
    background-position:0px 0px;  
    position:fixed;  
    bottom:95px;  
    color:white;  
    z-index:2;  
    cursor:pointer;  
    display:none;  
    _position:absolute;  
    _top:expression(eval(document.documentElement.scrollTop || document.body.scrollTop) +eval(document.documentElement.clientHeight || document.body.clientHeight)*0.7 +'px');  
    }  
.to_top_btn:hover{  
    background:url(../images/to-top.png);  
    background-position:0px 54px;  
    }  
  
/*-----------置顶按钮-----------*/  

添加公共脚本,在window.onload中添加方法:
//初始化置顶按钮位置  
$('.to_top_btn').css('right',($(window).width()-$('.container').width())/2-$('.to_top_btn').width()+"px");  
  
//置顶按钮  
$(window).scroll(function(){if($(document).scrollTop()>160){  
    $('.to_top_btn').fadeIn();  
    }else{  
        $('.to_top_btn').fadeOut();  
        }});  
$('.to_top_btn').click(function(){  
    var timer=setInterval(function(){  
    if($(document).scrollTop()==0){  
        clearInterval(timer);  
        }else{  
    $(document).scrollTop($(document).scrollTop()-30);  
    }  
    },5);  
});  

在需要的页面添加标签
<div class="to_top_btn"></div>  

相关文章

HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码