+1 vote

How to make scroll container do two things

  1. Scroll in the direction the mouse is pointing without a click. so for example, if you move the mouse to the right side of the container, it will scroll to the right

  2. the node inside the scroll container that you are hovering over scale-up. An example in my case would be a panel. So when my mouse hovers over this panel that is inside the scroll container, I want it to scale up. and when the mouse stops hovering over it, it goes back down to its original size. Sorta like a deck of card effects

can someone point me in the right direction, I tried a few things but they didn't work. Thanks

Godot version 3
in Engine by (27 points)

1 Answer

+4 votes
Best answer

Here's how I would accomplish #1:

extends ScrollContainer


const SCROLL_MARGIN = 16  # Unit: px
# Choose a multiple of 60 to prevent stuttering on 60Hz displays.
const SCROLL_SPEED = 120  # Unit: px/sec

onready var scroll_horizontal_float = float(scroll_horizontal)  # Unit: px


func _process(delta):
    var mouse_pos = get_local_mouse_position()

    if is_in_range(mouse_pos.y, 0, rect_size.y):
        if is_in_range(mouse_pos.x, 0, SCROLL_MARGIN):
            scroll_horizontal_float -= SCROLL_SPEED * delta
        elif is_in_range(mouse_pos.x, rect_size.x - SCROLL_MARGIN, rect_size.x):
            scroll_horizontal_float += SCROLL_SPEED * delta

        scroll_horizontal = int(round(scroll_horizontal_float))


func is_in_range(value, lower_bound, upper_bound):
    return lower_bound <= value and value <= upper_bound
by (361 points)
selected by

Thank you this helps alot!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.