所以我有一个固定宽度的组件,它有一个溢出-x-汽车。我决定隐藏滚动条,并将其替换为左右两个箭头/按钮。如果我点击左边,它会滚动到左边,反之亦然。如何实现此功能?
这是我的组件
<div className={` vertical-card w-7/12 flex flex-row overflow-x-scroll no-scrollbar pb-4`}>
{
dataConselor.map((item, index) => {
return <VerticalCard key={item.id} name={item.nama} specialist={item.specialist} shortdesc={item.shortdesc} img={item.img} />
})
}
</div>发布于 2022-04-17 08:39:42
const scrollable = useRef(null);
<div id="myElement" ref={scrollable}>
...
</div>const scrollIt = (toRight) => {
const scrollLength = ... //Calculate your scroll length however you want.
scrollable.current.scrollBy({left: scrollLength * (toRight ? 1 : -1), behavior: "smooth"});
}<div id="toLeft" onClick={()=>scrollIt(false)}>...</div>
<div id="toRight" onClick={()=>scrollIt(true)}>...</div>发布于 2022-04-17 08:32:43
当您使用顺风css时,您可以使用顺风角组件来实现这种行为。
在这里上有各种各样的carousals。
https://stackoverflow.com/questions/71900377
复制相似问题