我创建了一个可滚动区域,我正在尝试在图像下方添加一个滚动条(链接图像中的蓝色滚动条)
我目前拥有的可滚动区域的代码。
scroll = new ScrollComponent
opacity: 1.00
shadowBlur: 0
scroll.size = screen
Info.parent = scroll.content
scroll.scrollVertical = false
我创建了一个可滚动区域,我正在尝试在图像下方添加一个滚动条(链接图像中的蓝色滚动条)
我目前拥有的可滚动区域的代码。
scroll = new ScrollComponent
opacity: 1.00
shadowBlur: 0
scroll.size = screen
Info.parent = scroll.content
scroll.scrollVertical = false
我认为您正在尝试制作一个随着滚动而移动的滚动条,并显示用户滚动了多远,对吗?这是一些如何做到这一点的代码:
scrollbar.parent = scroll
# First make the width of the scrollbar relative to the size of the content.
scrollbar.width = (scroll.width / scroll.content.width) * scroll.width
# When the scroll is moved
scroll.onMove ->
# Calculate the width that we should scroll over
width = scroll.content.width - scroll.width
# Calculate the percentage that has currently been scrolled
percentage = scroll.scrollX / width
# Calculate how much space there for the scrollbar to move in
freeSpace = scroll.width - scrollbar.width
# Set the position of the scrollbar relative to the free space and the percentage scrolled
scrollbar.x = freeSpace * percentage
一个完整的例子在这里:https ://framer.cloud/QtcLD