首頁  >  文章  >  web前端  >  JS簡單實作滑動載入資料實例分享

JS簡單實作滑動載入資料實例分享

小云云
小云云原創
2018-01-09 14:03:122027瀏覽

本文主要介紹了JS簡單實作滑動載入資料的方法,涉及javascript事件回應及頁面元素屬性動態操作相關技巧,需要的朋友可以參考下,希望能幫助到大家。

//滑动
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;
}
//获取当前可视范围的高度
function getClientHeight()
{
 var clientHeight = 0;
 if (document.body.clientHeight && document.documentElement.clientHeight) {
   clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
 }else {
   clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
 }
   return clientHeight;
}
//获取文档完整的高度
function getScrollHeight()
{
   return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}
//绑定事件
window.onscroll = function ()
{
 if (getScrollTop() + getClientHeight() == getScrollHeight()) {
  //dosomething
 }
}

相關推薦:
javascript - js如何在滑動載入的時候限定滑動的載入次數

##Javascript vue.js表格分頁,ajax非同步載入資料

Bootstrap treeview實作動態載入資料及快速搜尋功能的實作

以上是JS簡單實作滑動載入資料實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn