How we can make an div element with scroll, to have vertical scrollbar top position 100px?
import React, { useState, useEffect, createRef } from "react";
const DatePicker = () => {
const myRef = createRef();
const [openToDateNew, setOpenToDate] = useState(openToDate)
const handleScrollBottom = () => {
console.log("reached bottom")
setOpenToDate(new Date(openToDateNew + 365 * 864e5));
const node = myRef.current;
node.scrollTop = 100;
}
const handleScrollTop = () => {
console.log("reached Top")
setOpenToDate(new Date(openToDateNew - 365 * 864e5));
}
return (
<ReactScrollDetector
debounceTime={200}
accuracy={50}
onScrollBottom={handleScrollBottom}
onScrollTop={handleScrollTop}>
<div ref={myRef} style={{ minHeight: "300px", maxHeight: "300px", overflow: "auto" }}>
</div>
</ReactScrollDetector>
);
};
<div ref={myRef} style={{ height: "300px", overflowY: "scroll" }}> </div>
after 300 px this will be scrollable or you can set height as per your requirement
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.