苹果橡皮筋解决办法react版本

import React, { useEffect, useRef } from 'react'
import './index3.less'
export default function Index3() {
    const box = useRef<HTMLDivElement>(null)
    const con = useRef<HTMLDivElement>(null)
    const input = useRef<HTMLInputElement>(null)
    useEffect(()=>{
        (con.current!.children[0] as HTMLDivElement).style.height = con.current!.offsetHeight +2 +'px'
        box.current!.scrollTop = 1
        box.current!.onscroll =()=>{
            // document.title = `${box.current!.scrollTop}`
            box.current!.scrollTop === 0 || box.current!.scrollTop === 2 ?box.current!.scrollTop = 1:console.log();
        }
    },[])
    document.ontouchmove =()=>{
        input.current!.blur()
    }
  return (
    <div className="mybox" ref={box}>
        <div className="header">
            <input type="text" ref={input}/>
        </div>
        <div className="con" ref={con}>
            <div>搜索记录</div>
        </div>
    </div>
  )
}
.mybox {
    position: fixed;
    width: 100vw;
    height: 100vh;
    overflow-y: scroll;
    display: flex;
    .header {
      position: fixed;
      width: 100vw;
      height: 100px;
      background:#F63866;
      input {
        width: 80%;
        height: 60px;
        border-radius: 50px;
        padding-left: 30px;
        border:none;
        display: block;
        margin:20px auto;
      }
    }
    .con {
      width: 100vw;
      flex:1;
      background-color: #ffffff;
      margin-top: 100px;
      div {
        text-align: center;
        font-size: 40px;
        font-weight: bold;
      }
    }
  }
  .mybox::-webkit-scrollbar {
    display: none;
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值