1
0

scroll_area_documentation.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.scroll_area)
  4. def main_demo() -> None:
  5. with ui.row():
  6. with ui.scroll_area().classes('w-32 h-32 border'):
  7. ui.label('I scroll. ' * 20)
  8. with ui.column().classes('p-4 w-32 h-32 border'):
  9. ui.label('I will not scroll. ' * 10)
  10. @doc.demo('Handling Scroll Events', '''
  11. You can use the `on_scroll` argument in `ui.scroll_area` to handle scroll events.
  12. The callback receives a `ScrollEventArguments` object with the following attributes:
  13. - `sender`: the scroll area that generated the event
  14. - `client`: the matching client
  15. - additional arguments as described in [Quasar's documentation for the ScrollArea API](https://quasar.dev/vue-components/scroll-area/#qscrollarea-api)
  16. ''')
  17. def scroll_events():
  18. position = ui.number('scroll position:').props('readonly')
  19. with ui.card().classes('w-32 h-32'):
  20. with ui.scroll_area(on_scroll=lambda e: position.set_value(e.vertical_percentage)):
  21. ui.label('I scroll. ' * 20)
  22. @doc.demo('Setting the scroll position', '''
  23. You can use `scroll_to` to programmatically set the scroll position.
  24. This can be useful for navigation or synchronization of multiple scroll areas.
  25. ''')
  26. def scroll_position():
  27. ui.number('position', value=0, min=0, max=1, step=0.1,
  28. on_change=lambda e: area1.scroll_to(percent=e.value)).classes('w-32')
  29. with ui.row():
  30. with ui.card().classes('w-32 h-48'):
  31. with ui.scroll_area(on_scroll=lambda e: area2.scroll_to(percent=e.vertical_percentage)) as area1:
  32. ui.label('I scroll. ' * 20)
  33. with ui.card().classes('w-32 h-48'):
  34. with ui.scroll_area() as area2:
  35. ui.label('I scroll. ' * 20)
  36. doc.reference(ui.scroll_area)