亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么不能實現呢?

為什么不能實現呢?

筱羅卜 2016-09-17 17:52:39
按照視頻教的方法,我自己根據視頻里的代碼寫的,為什么回到頂部那張圖就是不能顯示?
查看完整描述

1 回答

?
Caballarii

TA貢獻1123條經驗 獲得超629個贊

代碼貼出來

查看完整回答
反對 回復 2016-09-17
  • 筱羅卜
    筱羅卜
    //index.htm <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Javascript回到頂部效果</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="script.js"></script> </head> <body> <div class="box"> <img src="image/pic1.gif" /> </div> <a href="javascript:;" id="btn" title="回到頂部"></a> </body> </html>
  • 筱羅卜
    筱羅卜
    //style.css /* CSS Document */ .box{ width:1200px; margin:0 auto; } .btn{ width:37px; height:38px; position:fixed; left:50%; margin:-left:630px; bottom:30px; background:url(image/btn.png) no-repeat left top;} #btn:hover{ background:url(image/btn.png) no-repeat left -38px; }
  • 筱羅卜
    筱羅卜
    //script.js // JavaScript Document //頁面加載完畢后觸發 window.onload=function(){ var obtn=document.getElementById('btn'); var timer=null; var isTop=true; //滾動條滾動式觸發 window.onscroll=funcyion(){ if(!isTop){ clearInterval(timer); } isTop=false; } obtn.onclick=function(){ //設置定時器 timer=setInterval(function(){ //獲取滾動條距離頂部的高度 var osTop=document.documentElement.scrolTop || document.body.scrollTop; var ispeed=Math.floor(-osTop/5); isTop=true; document.documentElement.scrolTop = document.body.scrollTops = osTop + ispeed; console.log(osTop - ispeed); if(osTop==0){ clearInterval(timer); } },30); } }
點擊展開后面1
  • 1 回答
  • 0 關注
  • 894 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號