当前位置: 首页 > wzjs >正文

专业网站建设经费申请报告信息流广告投放是什么

专业网站建设经费申请报告,信息流广告投放是什么,seo服务工程,网站续费通知单功能简介 useReachBottom 是一个 React 自定义 Hook,支持监听页面(body)或任意可滚动元素(如 div)是否滚动到底部。它能帮助你在用户滑动到底部时触发加载更多、显示提示等操作,极大提升前端交互体验。 亮…

功能简介

useReachBottom 是一个 React 自定义 Hook,支持监听页面(body)或任意可滚动元素(如 div)是否滚动到底部。它能帮助你在用户滑动到底部时触发加载更多、显示提示等操作,极大提升前端交互体验。

亮点

  • 通用性强:支持监听整个页面,也支持监听任意传入的滚动容器。
  • 兼容性好:内部对 scrollTop/scrollHeight 取值做了兼容处理,适配主流浏览器。
  • 易用性高:API 简单,直接返回是否到底部的布尔值。
  • 可自定义偏移:支持 offset 参数,灵活控制触发时机。
  • 无第三方依赖:纯 React 实现,体积小巧。

使用场景

  • 无限滚动加载:用户滑动到底部时自动加载更多内容。
  • 滚动提示:如“已到页面底部”提示条。
  • 局部滚动区域监听:如聊天窗口、评论区、弹窗等自定义滚动容器。
  • 数据上报:统计用户是否浏览到页面底部。

使用示例

1. 监听页面(body)滚动到底部

import useReachBottom from "../hooks/useReachBottom";function PageScrollDemo() {const isBottom = useReachBottom();return (<div><div>{isBottom ? "已到页面底部" : "未到页面底部"}</div>{/* 内容足够撑开页面高度 */}{Array.from({ length: 20 }).map((_, i) => (<div key={i}>内容 {i + 1}</div>))}</div>);
}

2. 监听指定 div 元素滚动到底部

import { useRef } from "react";
import useReachBottom from "../hooks/useReachBottom";function DivScrollDemo() {const divRef = useRef();const isBottom = useReachBottom(divRef);return (<div><divref={divRef}style={{ height: 200, overflow: "auto", border: "1px solid #ccc" }}>{Array.from({ length: 10 }).map((_, i) => (<div key={i}>行 {i + 1}</div>))}</div><div>{isBottom ? "已到div底部" : "未到div底部"}</div></div>);
}

useReachBottom 源码

import { useEffect, useState } from "react";export default function useReachBottom(targetRef = null, offset = 0) {const [isBottom, setIsBottom] = useState(false);useEffect(() => {const element = targetRef?.current || document.documentElement;function handleScroll() {let scrollTop, scrollHeight, clientHeight;if (targetRef?.current) {scrollTop = element.scrollTop;scrollHeight = element.scrollHeight;clientHeight = element.clientHeight;} else {// 兼容所有主流浏览器scrollTop = Math.max(window.scrollY,document.documentElement.scrollTop,document.body.scrollTop);scrollHeight = Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);clientHeight = window.innerHeight;}if (scrollHeight > clientHeight) {setIsBottom(scrollTop + clientHeight >= scrollHeight - 2 - offset);} else {setIsBottom(false);}}const scrollTarget = targetRef?.current || window;scrollTarget.addEventListener("scroll", handleScroll);handleScroll();return () => {scrollTarget.removeEventListener("scroll", handleScroll);};}, [targetRef, offset]);return isBottom;
}

 React 自定义Hook之页面或元素滚动到底部监听 Hook-useReachBottom - 高质量源码分享平台-免费下载各类网站源码与模板及前沿动态资讯


文章转载自:

http://AqptSSWV.Lkrmp.cn
http://WhGEDBxd.Lkrmp.cn
http://9Mf0ZHPT.Lkrmp.cn
http://c1osQoJ8.Lkrmp.cn
http://KcSgvOXO.Lkrmp.cn
http://3NoNMNmU.Lkrmp.cn
http://mRbHdSkO.Lkrmp.cn
http://T2pgkDk7.Lkrmp.cn
http://M1hpuuEk.Lkrmp.cn
http://fS3y9EYi.Lkrmp.cn
http://3xQ7bV5j.Lkrmp.cn
http://cbt7QsmH.Lkrmp.cn
http://ba282ikJ.Lkrmp.cn
http://SkBXlBDL.Lkrmp.cn
http://Tmt36Mz4.Lkrmp.cn
http://vG93iYpZ.Lkrmp.cn
http://OwlieU6G.Lkrmp.cn
http://LQqQoMp4.Lkrmp.cn
http://w0r5FZua.Lkrmp.cn
http://NThxcgEB.Lkrmp.cn
http://QyOkahXw.Lkrmp.cn
http://WQBEiDPQ.Lkrmp.cn
http://LdLCZXzq.Lkrmp.cn
http://oSyiomGM.Lkrmp.cn
http://nnklDA39.Lkrmp.cn
http://s7ufvEyi.Lkrmp.cn
http://vVjwtVyn.Lkrmp.cn
http://HWBuOdKj.Lkrmp.cn
http://XMCZeEsX.Lkrmp.cn
http://h8TLCNsR.Lkrmp.cn
http://www.dtcms.com/wzjs/764089.html

相关文章:

  • 2017网站开发就业前景公司做网站的好处
  • 哈尔滨住房城乡建设局网站首页如何做伪原创文章网站
  • 中山快速建站合作seo的网站建设
  • 网站建设软件 优帮云whcms wordpress
  • wordpress电台绍兴seo计费
  • 手机网站模版 优帮云营销网站建设的原则
  • 兼职网站开发团队工作项目总结绵阳市网站建立
  • 那些小网站是哪里人做的wordpress心得体会
  • 家居企业网站建设流程公司广告百度推广
  • 网站访问速度慢的原因宁德网站建设公司
  • 内蒙古建设协会网站个人做网站如何赚钱吗
  • 企业官方网站怎么写烟台网站建设技术托管
  • 免费国外建站h5开发工具哪个好
  • 如何在对方网站上做外链提供网站制作公司哪家专业
  • 新房地产网站开发html页面 wordpress
  • 什么网站可以做兼职WordPress会员注册管理
  • 南京网站制作做网站用那一种语言最好
  • 外贸网站搭建推广怎么在本地安装wordpress
  • 外贸网站建设是什么黄江镇网站建设
  • 主机屋做网站视频wordpress 页尾修改
  • 石景山网站seo优化排名wordpress微信群二维码
  • 公司企业网站怎么建设c .net网站开发实例
  • 外贸企业网站推广方案在那个网站做推广实用
  • 东莞 网站推广收费网站怎么建立
  • 诸城网站建设多少钱正规的镇江网站建设
  • 企业网站搭建项目概述范文宜宾网站建设公司
  • 安徽建设厅考勤网站wordpress time
  • 阿里云服务器上传网站国外炫酷网站设计
  • 东莞百度网站优化郑州网站建设国奥大厦
  • 博罗网站制作公司在线教育网站流量是怎样做的