import React, { useRef, useEffect } from 'react' import BScroll from '@better-scroll/core' import NestedScroll from '@better-scroll/nested-scroll' BScroll.use(NestedScroll) const outerOpenData = [ '----Outer Start----', '๐Ÿ‘†๐Ÿป outer scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿ™‚ ๐Ÿค” ๐Ÿ˜„ ๐Ÿคจ ๐Ÿ˜ ๐Ÿ™ƒ ', '๐Ÿ‘†๐Ÿป outer scroll ๐Ÿ‘‡๐Ÿป ', ] const outerCloseData = [ '๐Ÿ‘†๐Ÿป outer scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿ™‚ ๐Ÿค” ๐Ÿ˜„ ๐Ÿคจ ๐Ÿ˜ ๐Ÿ™ƒ ', '๐Ÿ‘†๐Ÿป outer scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿ˜” ๐Ÿ˜• ๐Ÿ™ƒ ๐Ÿค‘ ๐Ÿ˜ฒ ๐Ÿ˜ฒ ', '๐Ÿ™‚ ๐Ÿค” ๐Ÿ˜„ ๐Ÿคจ ๐Ÿ˜ ๐Ÿ™ƒ ', '๐Ÿ‘†๐Ÿป outer scroll ๐Ÿ‘‡๐Ÿป ', '----Outer End----', ] const middleOpenData = [ '----Middle Start----', '๐Ÿ‘†๐Ÿป middle scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ', ] const middleCloseData = [ '๐Ÿ‘†๐Ÿป middle scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ', '๐Ÿ‘†๐Ÿป middle scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ', '๐Ÿ‘†๐Ÿป middle scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ', '๐Ÿ‘†๐Ÿป middle scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿš– ๐Ÿš– ๐Ÿš– ๐Ÿš– ๐Ÿš– ๐Ÿš– ', '๐Ÿ‘†๐Ÿป middle scroll ๐Ÿ‘‡๐Ÿป ', 'โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป ', '----Middle End----', ] const innerData = [ '------Inner Start-----', '๐Ÿ˜€ ๐Ÿ˜ ๐Ÿ˜‚ ๐Ÿคฃ ๐Ÿ˜ƒ ๐Ÿ™ƒ ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿ™‚ ๐Ÿค” ๐Ÿ˜„ ๐Ÿคจ ๐Ÿ˜ ๐Ÿ™ƒ ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿ˜” ๐Ÿ˜• ๐Ÿ™ƒ ๐Ÿค‘ ๐Ÿ˜ฒ ๐Ÿ˜ ๐Ÿ™ƒ ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ๐Ÿฃ ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿฅ ๐Ÿฅ ๐Ÿฅ ๐Ÿฅ ๐Ÿฅ ๐Ÿฅ ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ๐Ÿค“ ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ๐Ÿฆ” ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ๐Ÿ™ˆ ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', '๐Ÿš– ๐Ÿš– ๐Ÿš– ๐Ÿš– ๐Ÿš– ๐Ÿš– ', '๐Ÿ‘†๐Ÿป inner scroll ๐Ÿ‘‡๐Ÿป ', 'โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป โœŒ๐Ÿป ', '-----Inner End-----', ] const handleOuterClick = () => { alert('clicked outer item') } const handleMiddleClick = () => { alert('clicked middle item') } const handleInnerClick = () => { alert('clicked inner item') } const TripleVertical = () => { const outerWrapperRef = useRef(null) const middleWrapperRef = useRef(null) const innerWrapperRef = useRef(null) useEffect(() => { const outerScroll = new BScroll(outerWrapperRef.current, { nestedScroll: { groupId: 'triple-nested-scroll', // groupId is a string or number }, click: true, }) const middleScroll = new BScroll(middleWrapperRef.current, { nestedScroll: { groupId: 'triple-nested-scroll', // groupId is a string or number }, probeType: 2, click: true, }) middleScroll.on('scroll', () => { console.log('middleScroll scroll') }) const innerScroll = new BScroll(innerWrapperRef.current, { // please keep the same groupId as above // all scrolls will be controlled by the same nestedScroll instance nestedScroll: { groupId: 'triple-nested-scroll', }, probeType: 2, click: true, }) innerScroll.on('scroll', () => { console.log('innerScroll scroll') }) innerScroll.on('scrollEnd', () => { console.log('innerScroll scrollEnd') }) return () => { outerScroll.destroy() middleScroll.destroy() innerScroll.destroy() } }, []) return (
    {outerOpenData.map((item, index) => (
  • {item}
  • ))}
    {middleOpenData.map((item, index) => (
  • {item}
  • ))}
    {innerData.map((item, index) => (
  • {item}
  • ))}
    {middleCloseData.map((item, index) => (
  • {item}
  • ))}
    {outerCloseData.map((item, index) => (
  • {item}
  • ))}
) } export default TripleVertical