's'
This commit is contained in:
@@ -16,9 +16,10 @@ function getPb() {
|
||||
const LazyChunk = React.memo(({ html, estimatedHeight, forceVisible }) => {
|
||||
const [visible, setVisible] = useState(forceVisible);
|
||||
const ref = useRef(null);
|
||||
const show = forceVisible || visible;
|
||||
|
||||
useEffect(() => {
|
||||
if (forceVisible) { setVisible(true); return; }
|
||||
if (forceVisible) return;
|
||||
if (visible) return;
|
||||
const el = ref.current;
|
||||
if (!el) return;
|
||||
@@ -35,7 +36,7 @@ const LazyChunk = React.memo(({ html, estimatedHeight, forceVisible }) => {
|
||||
return () => observer.disconnect();
|
||||
}, [forceVisible, visible]);
|
||||
|
||||
if (visible) {
|
||||
if (show) {
|
||||
return <div className="chunk-enter" dangerouslySetInnerHTML={{ __html: html }} />;
|
||||
}
|
||||
return <div ref={ref} className="chunk-placeholder" style={{ minHeight: estimatedHeight }} />;
|
||||
@@ -195,18 +196,29 @@ const Book = () => {
|
||||
};
|
||||
}, [contentLoading]);
|
||||
|
||||
const handleJump = useCallback((text) => {
|
||||
const handleJump = useCallback((index) => {
|
||||
setForceShowAll(true);
|
||||
setTimeout(() => {
|
||||
if (!contentRef.current) return;
|
||||
const h1s = contentRef.current.querySelectorAll("h1");
|
||||
for (let h1 of h1s) {
|
||||
if (h1.textContent.trim() === text.trim()) {
|
||||
h1.scrollIntoView({ behavior: "smooth" });
|
||||
break;
|
||||
setshow(false);
|
||||
|
||||
const run = () => {
|
||||
const root = contentRef.current;
|
||||
if (!root) return;
|
||||
const h1s = root.querySelectorAll("h1");
|
||||
const el = h1s[index];
|
||||
if (el) {
|
||||
try {
|
||||
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
} catch (_) {
|
||||
const top = el.getBoundingClientRect().top + (window.pageYOffset || document.documentElement.scrollTop) - 60;
|
||||
window.scrollTo({ top: Math.max(0, top), behavior: "smooth" });
|
||||
}
|
||||
}
|
||||
}, 200);
|
||||
};
|
||||
|
||||
run();
|
||||
setTimeout(run, 100);
|
||||
setTimeout(run, 300);
|
||||
setTimeout(run, 600);
|
||||
}, []);
|
||||
|
||||
const submitPayForm = (xorpayUrl, xorpayParams) => {
|
||||
@@ -284,7 +296,7 @@ const Book = () => {
|
||||
show={show}
|
||||
mask
|
||||
items={activeHeaders}
|
||||
onItemClick={(index) => handleJump(activeHeaders[index])}
|
||||
onItemClick={(index) => handleJump(index)}
|
||||
onClose={() => setshow(false)}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user