<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html?xmlns="http://www.w3.org/1999/xhtml"?xml:lang="en">
<head>
<meta?http-equiv="Content-Type"?content="text/html;charset=UTF-8"?/>
<title>Javascript?返回頂部</title>
<style?type="text/css">
#btn?{width:40px;?height:40px;?position:fixed;?display:none;right:65px;?bottom:10px;?background:url(images/top_bg.png)?no-repeat?left?top;}
#btn:hover?{background:url(images/top_bg.png)?no-repeat?0?-39px;}
.bg?{width:1190px;?margin:0?auto;}
</style>
</head>
<body>
<a?href="javascript:;"?id="btn"?title="回到頂部"></a>
<div>
<img?src="images/tb_bg.jpg"?alt=""?/>
</div>
<script>?
window.onload=function(){??
var?time=null;
var?btn=document.getElementById("btn")
btn.onclick=function(){
time=setTimeout(app,300)
function?app(){
var?scroll=document.body.scrollTop||document.documentElement.scrollTop;
??document.body.scrollTop=0;
?
?}?
}
var?clientHeight=document.documentElement.clientHeight;
var?scroll=document.documentElement.scrollTop||document.body.scrollTop;
????window.onscroll=function(){
????if(scroll>=clientHeight/2){
?????btn.style.display="blcok";
?????
????}
????else{btn.style.display="none"}
}?
???}?
?
</script>
</body>
</html>滾動沒有觸發(fā)事件,btn沒有出現(xiàn),不知道哪里錯了
滾動觸發(fā)函數(shù)
qq_小白_7
2016-05-05 11:29:55