js如何實(shí)現(xiàn)返回頂部效果

這篇文章主要為大家展示了“js如何實(shí)現(xiàn)返回頂部效果”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“js如何實(shí)現(xiàn)返回頂部效果”這篇文章吧。

長(zhǎng)汀網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),長(zhǎng)汀網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為長(zhǎng)汀上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的長(zhǎng)汀做網(wǎng)站的公司定做!

代碼如下:

<!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=utf-8" />
<title>JS點(diǎn)擊按鈕到頁(yè)面最底部/返回頁(yè)面頂部代碼</title>
<style type="text/css">
 #back-to-top{ position: fixed; bottom: 50px; right: 10%; }
</style>
</head>
<body>
<div ></div>
<div id="back-to-top">
 <a href="#top" rel="external nofollow" >返回頂部</a>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
 <script type="text/javascript">
 $(document).ready(function(){
  //首先將#back-to-top隱藏
  $("#back-to-top").hide();
  //當(dāng)滾動(dòng)條的位置處于距頂部100像素以下時(shí),跳轉(zhuǎn)鏈接出現(xiàn),否則消失
  $(function () {
    $(window).scroll(function(){
    if ($(window).scrollTop()>100){
    $("#back-to-top").fadeIn(100);
    }
    else
    {
    $("#back-to-top").fadeOut(100);
    }
    });
    //當(dāng)點(diǎn)擊跳轉(zhuǎn)鏈接后,回到頁(yè)面頂部位置
    $("#back-to-top").click(function(){
    $('body,html').animate({scrollTop:0},"speed");
    return false;
    });
    });
    });
 </script>
</body>
</html>

以上是“js如何實(shí)現(xiàn)返回頂部效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文名稱:js如何實(shí)現(xiàn)返回頂部效果
轉(zhuǎn)載注明:http://muchs.cn/article4/ppjgie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、電子商務(wù)網(wǎng)站維護(hù)、網(wǎng)站設(shè)計(jì)公司、外貿(mào)網(wǎng)站建設(shè)網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司