coffeescriptframerjs

FramerJS - Horizontal scrollbar with the scroll component


I have created a scrollable area and i am trying to add a scrollbar underneath the images (the blue scrollbar in the linked image)

Code that i currently have for the scrollable area.

scroll = new ScrollComponent
opacity: 1.00
shadowBlur: 0
scroll.size = screen
Info.parent = scroll.content 
scroll.scrollVertical = false

Scroll


Solution

  • I think you're trying to make a scrollbar that moves with the scrolling and shows how far along the user has scrolled, right? Here's some code how to do that:

    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
    

    A full example is here: https://framer.cloud/QtcLD