国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實現簡單的回到頂部totop功能示例

2019-11-19 15:10:01
字體:
來源:轉載
供稿:網友

本文實例講述了jQuery實現簡單的回到頂部totop功能。分享給大家供大家參考,具體如下:

<!DOCTYPE html><html> <head>  <meta charset="UTF-8">  <title>回到頂部</title>  <style type="text/css">   body{    width: 100%;    height: 10000px;   }   #totop{    width: 50px;    height: 50px;    line-height: 50px;    background: magenta;    font-size: 20px;    position: fixed;    right: 50px;    bottom: 50px;   }  </style> </head> <body> </body> <script src="js/jquery-1.8.3.min.js" ></script> <script>  //寫在common.js文件中用來調用即可  //1獲取滾動條當前的位置  function getScrollTop() {   var scrollTop = 0;   if (document.documentElement && document.documentElement.scrollTop) {    scrollTop = document.documentElement.scrollTop;   } else if (document.body) {    scrollTop = document.body.scrollTop;   }   return scrollTop;  };  //2獲取文檔完整的高度  function getScrollHeight() {   return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);  };  //3回到頂部  function toTop(n) {   $(window).on('scroll', function() {    //console.log(getScrollTop()+"!"+getScrollHeight());    if ($("#totop").size() > 0) {     if (getScrollTop() < $(window).height() * n) {      $("#totop").remove();     }    } else {     if (getScrollTop() >= $(window).height() * n) {      $("body").after("<div id='totop'>totop</div>");      //插入了新標簽 ,記得添加樣式!      $("#totop").on('click', function() {       scroll(0,200);      });     }    }   });  };  //xxx.js文件來執行  $(function(){   toTop(2);  }) </script></html>

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery窗口操作技巧總結》、《jQuery常用插件及用法總結》、《jquery中Ajax用法總結》、《jQuery表格(table)操作技巧匯總》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結

希望本文所述對大家jQuery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昂仁县| 本溪市| 安乡县| 和顺县| 治多县| 镇坪县| 仁化县| 同江市| 曲靖市| 北票市| 象州县| 手游| 金华市| 汨罗市| 京山县| 石城县| 汝州市| 德阳市| 海原县| 瓮安县| 锦屏县| 平昌县| 永城市| 凉城县| 定边县| 任丘市| 刚察县| 胶州市| 策勒县| 乌海市| 进贤县| 勐海县| 旬阳县| 板桥市| 海盐县| 淳化县| 焦作市| 墨玉县| 高邑县| 兴海县| 手机|