每次看淘寶,看微信,都回有回到頂部的小logo,小圖標,或者雙擊返回頂部。所以就學習了如何返回頂部的操作,一開始是聯想html中的鏈接描點,在開頭出設置個標簽,下面點擊另外一個標志回去。有三種覺得比較適合使用,就保留下來。
第一種 添加一個超鏈接,然后給其href="#top",則可以使用 <a href="#top" class="btn" title="回到頂端"></a>
第二種 href指向特定的id <body id="goTop"> <div class="box"> <img src="1.jpg"> <img src="1.jpg"> <img src="1.jpg"> </div> <a href="#goTop" class="btn" title="回到頂端"></a> </body>
第三種 用scrollTo(0,0)中的x、y的值來跳轉到頁面的具體位置。 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title>返回頂端</title> <link rel="stylesheet" type="text/css" href="hello.css"> </head> <body id="goTop"> <div class="box"> <img src="1.jpg"> <img src="1.jpg"> <img src="1.jpg"> </div> <a href="javascript:window.scrollTo(0,0)" class="btn" title="回到頂端"></a> </body> </html>