back to top & back to bottom

infinite auto load more & infinite scroll & load more

https://codepen.io/xgqfrms/pen/NZVvGM

  1. "use strict";
  2. /**
  3. *
  4. * @author xgqfrms
  5. * @license MIT
  6. * @copyright xgqfrms
  7. *
  8. * @description scrollBottomAutoLoadMore
  9. * @augments
  10. * @example
  11. * @link
  12. *
  13. */
  14. // utils
  15. let log = console.log;
  16. let error = console.error;
  17. let box = document.querySelector(`[data-dom="outbox"]`);
  18. // bottom: 556.59375
  19. // height: 525.59375
  20. // left: 135
  21. // right: 405
  22. // top: 31
  23. // width: 270
  24. // x: 135
  25. // y: 31
  26. // height: 525.59375 ~= 526
  27. // ch = 526
  28. // 1562 - 1036 = 526
  29. // sh = 1562
  30. // st = 1036
  31. // ch = 526
  32. // cw = 253
  33. // oh = 526
  34. // ow = 270
  35. // sh = 1562
  36. // sw = 253
  37. // st = 1036
  38. let isTriggerOnce = true;
  39. const scrollBottomAutoLoadMore = (debug = false) => {
  40. for (let i = 0; i < 20; i++) {
  41. let template = `<div class="innerbox" data-dom="innerbox">${i + 1}</div>`;
  42. box.insertAdjacentHTML(`beforeend`, template);
  43. }
  44. let BoundingClientRect = box.getBoundingClientRect();
  45. let ClientRects = box.getClientRects();
  46. // log(`BoundingClientRect =`, BoundingClientRect);
  47. // log(`ClientRects`, ClientRects);
  48. // Event
  49. box.addEventListener(`scroll`, (e) => {
  50. // log(`e =`, e);
  51. // log(`e.target =`, e.target);
  52. // clientHeight, offsetHeight, scrollHeight
  53. let ch = e.target.clientHeight;
  54. let cw = e.target.clientWidth;
  55. // log(`ch =`, ch);
  56. // log(`cw =`, cw);
  57. let oh = e.target.offsetHeight;
  58. let ow = e.target.offsetWidth;
  59. // log(`oh =`, oh);
  60. // log(`ow =`, ow);
  61. let sh = e.target.scrollHeight;
  62. let sw = e.target.scrollWidth;
  63. // log(`sh =`, sh);
  64. // log(`sw =`, sw);
  65. let st = e.target.scrollTop;
  66. // log(`st =`, st);
  67. let trigger = (sh - st) < (ch + 50) ? true : false;
  68. let triggerValue = (sh - st) < (ch + 50);
  69. if (trigger && isTriggerOnce) {
  70. alert(`trigger loadMore function!`);
  71. isTriggerOnce = false;
  72. for (let i = 0; i < 10; i++) {
  73. let template = `<div class="innerbox" data-dom="innerbox">${i + 1}</div>`;
  74. box.insertAdjacentHTML(`beforeend`, template);
  75. }
  76. setTimeout(() => {
  77. alert(`Ajax & fetch data success!`);
  78. isTriggerOnce = true;
  79. }, 1000);
  80. } else {
  81. // do nothing
  82. // log(`sh =`, sh);
  83. // log(`st =`, st);
  84. // log(`ch =`, ch);
  85. log(`(sh - st) =`, (sh - st));
  86. log(`(ch - 50) =`, (ch + 50));
  87. log(`triggerValue =`, triggerValue);
  88. }
  89. // clientHeight: 526
  90. // clientWidth: 346
  91. // offsetHeight: 526
  92. // offsetLeft: 182
  93. // offsetTop: 31
  94. // offsetWidth: 363
  95. // scrollHeight: 1562
  96. // scrollLeft: 0
  97. // scrollTop: 1036
  98. // scrollWidth: 346
  99. });
  100. // MouseEvent
  101. box.addEventListener(`click`, (e) => {
  102. // log(`e =`, e);
  103. // log(`e.target =`, e.target);
  104. // pageX, pageY, screenX, screenY, clientX, and clientY
  105. let px = e.pageX;
  106. let py = e.pageY;
  107. // let sx = e.screenX;
  108. // let sy = e.screenY;
  109. // let cx = e.clientX;
  110. // let cy = e.clientY;
  111. log(`px =`, px);
  112. log(`py =`, py);
  113. let lx = e.layerX;
  114. let ly = e.layerY;
  115. let mx = e.movementX;
  116. let my = e.movementY;
  117. let ox = e.offsetX;
  118. let oy = e.offsetY;
  119. });
  120. };
  121. window.addEventListener("DOMContentLoaded", (event) => {
  122. console.log("DOM fully loaded and parsed");
  123. scrollBottomAutoLoadMore();
  124. });
  125. // export default scrollBottomAutoLoadMore;
  126. // export {
  127. // scrollBottomAutoLoadMore,
  128. // };

https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll

https://zzk.cnblogs.com/my/s/blogpost-p?Keywords=scroll

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有️xgqfrms, 禁止转载 ️,侵权必究️!


back to top & back to bottom的更多相关文章

  1. Altium Designer16 如何分别导出TOP层和BOTTOM层

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明. 作者:struct_mooc 博客地址:https://www.cnblogs.com/stru ...

  2. menu({postion:{my:"left top"},at:"right bottom"})里的my与at会冲突吗

    my(默认值:"center")类型:String描述:定义被定位元素上对准目标元素的位置:"horizontal vertical" 对齐方式.一个单一的值, ...

  3. 每天CSS学习之top/left/right/bottom

    top:值域是数值或百分比,正负都可以.该值表示 距离顶部有多少像素.例如top:10px:即距离顶部10个像素. left/right/bottom与top如出一辙,只是方向不一样而已. 这些属性一 ...

  4. (四)学习CSS之position、bottom、left、right和top属性

    参考:http://www.w3school.com.cn/cssref/pr_class_position.asp position 属性规定元素的定位类型. 这个属性定义建立元素布局所用的定位机制 ...

  5. css top,right,bottom,left设置为0有什么用?它和width:100%和height:100%有什么区别?

     壹 ❀ 引 当我们使用position属性时,总免不了与top,left,right,bottom四个属性打交道,那么这四个属性都设置为0时有什么用,与宽高设置100%又有什么区别?本文对此展开讨论 ...

  6. vertical-align:top属性

    vertical-align这个是设置元素的垂直排列的. 用来定义行内元素的基线相对于该元素所在行的基线的垂直对齐. 它的值比较多:baseline | sub | super | top | tex ...

  7. Top值

    业务开发中经常会用到元素或者浏览器窗口的各种top值,最近开发组件的过程中也遇到各种问题,因此决定好好总结一下. 常见的top值 scrollTop Element.scrollTop 属性可以获取或 ...

  8. css 样式中 margin padding和top类定位的区别

    1 margin margin 是外边距的意思,是边框到外部另一元素之间的距离,允许使用负值 语法结构: margin:5px auto;                  意思上下为5,左右平均居中 ...

  9. Jquery mobiscroll 移动设备(手机)wap日期时间选择插件以及滑动、滚动插件

    Jquery Mobiscroll是一个用于触摸设备(Android phones, iPhone, iPad, Galaxy Tab)的日期和时间选择器jQuery插件.以及各种滑动插件 可以让用户 ...

随机推荐

  1. 使用jiffies的时间比较函数time_after、time_before

    1. jiffies简介 首先,操作系统有个系统专用定时器(system timer),俗称滴答定时器,或者系统心跳. 全局变量jiffies取值为自操作系统启动以来的时钟滴答的数目,在头文件< ...

  2. LOJ10081

    USACO 201 Jan. Gold Farmer John 正在一个新的销售区域对他的牛奶销售方案进行调查.他想把牛奶送到 T 个城镇 ,编号为 1 到 T.这些城镇之间通过 R 条道路(编号为 ...

  3. Oracle数据库查询锁表及解锁

    一.查询哪些表被锁以及查看锁表得会话及操作系统进程ID 其中locked_mode为锁的级别,spid为数据库所在操作系统的进程id select c.sid, c.serial#, c.userna ...

  4. SparkStreaming与Kafka,SparkStreaming接收Kafka数据的两种方式

    SparkStreaming接收Kafka数据的两种方式 SparkStreaming接收数据原理 一.SparkStreaming + Kafka Receiver模式 二.SparkStreami ...

  5. phpstorm如何设置字体

    最近上手了一款轻量级IDE phpStorm,可是就在调整编辑器字体大小时却遇到问题了, 发现字体大小无法调整,另外还有字体大小往左还有个"√",始终无法去掉,这个勾限制了字体系列 ...

  6. Java中的fail-fast和 fail-safe 的区别

    在我们详细讨论这两种机制的区别之前,首先得先了解并发修改. 1.什么是同步修改? 当一个或多个线程正在遍历一个集合Collection,此时另一个线程修改了这个集合的内容(添加,删除或者修改).这就是 ...

  7. nginx反向代理signalr

    asp.net core应用常常要通过nginx来反向代理, 普通的web api配置asp.net core反向代理比较常见, 如果在应用中集成了signalr, 如何使用nginx来反代呢? ng ...

  8. shell脚本的使用该熟练起来了,你说呢?(篇一)

    作者:良知犹存 转载授权以及围观:欢迎添加微信公众号:羽林君

  9. 使用TCP发送文件

    客户端 package com.zy.demo3; import java.io.File; import java.io.FileInputStream; import java.io.IOExce ...

  10. 配置VS2013 + opencv 2.4.10

    其实我内心是极力反对装这么老的版本的,但是要交课堂作业~~好无奈 [注] : 如果按照本文配置不成功,可以试一下其他博客里面的配置(多试一试总能成功的) https://jingyan.baidu.c ...