混動效果沒有出來
看了一下代碼沒有出錯啊,不知道為什么沒有混動效果。而且我混動的那個圖片定義樣式只能在html里面設(shè)置才出來,放到css里面調(diào)用就沒有出來,感覺好奇怪。求解??!
代碼如下:<!doctype html/>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="css/srcoll-to-top.css"/>
<script type="text/javasript" src="jQuery/scroll-to-top.js"></script>
<title>javascript實現(xiàn)回到頂部</title>
<style type="text/css">
?? ?
??? #btn{
?? ?width:40px;
?? ?height:40px;
?? ?position:fixed;
?? ?left:50%;
?? ?margin-left:600px;
?? ?bottom:30px;
?? ?background:url(images/top_bg.png)no-repeat left top;
??? }
??? #btn:hover{
?? ?background:url(images/top_bg.png)no-repeat left -40px;
??? }
?? ?
?? ?</style>
</head>
<body>
<a href="javascript:;" id="btn" title="回到頂部"></a>
<!-- 這里href要是為空,那么點擊按鈕時是默認直接回到頂部的,這里是為了阻止瀏覽器默認行為。-->
<div class="box">
<img src="images/tb_bg.jpg" alt="" />
</div>
</body>
</html>
scroll-to-top.js
/*頁面加載完畢后觸發(fā)*/
window.onload=function(){
?? ?var obtn=document.getElementById('btn') ;? /*獲取id*/
?? ?var time = null;
?? ?obtn.onclick=function(){?? ??? ?/*綁定事件*/
?? ???? timer = setInterval(function(){??? /*設(shè)置定時器*/
?? ??? ??? ?var osTop =?? ?document.documentElement.scrollTop || document.body.scrollTop;? /*獲取混動條距離頂部的高度,還有判斷選擇,解決瀏覽器兼容性問題。*/
?? ??? ?document.documentElement.scrollTop = cocument.body.scrollTop -= 50; /*頁面每次往上走的距離*/
?? ??? ?},30);
?? ??? ?
?? ?}
?? ?
}
2016-12-14
改了也沒有效果啊。是什么問題???
2016-12-13
最后一句,document拼錯了