> For the complete documentation index, see [llms.txt](https://docs.matestack.io/matestack-ui-bootstrap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.matestack.io/matestack-ui-bootstrap/2.1/api/components/scrollspy.md).

# Scrollspy

The Bootstrap `scrollspy` component, implemented in Ruby. Use it like any other matestack component in your apps, pages and components. It offers customizable options to simply achieve what is possible in bootstrap with this component. See below for more information about the possible options.

## `bs_scrollspy(*args, &block)`

*use only when you want to apply the scrollspy behavior to a specific element on your UI (other than `body`)*

Returns a `div` with applied bootstrap scrollspy data attributes and `position: relative;` containing content specified by a block. Also the scrollspy is customizable with the following options:

**Required options**

* `:height` - Defines the height for the scrollable container, can be an Integer which will be interepreted as `Xpx`, or a custom String like `"20em"`

**Optional options**

* `:offset` - Pixels to offset from top when calculating position of scroll, by default 10
* `:method` - Finds which section the spied element is in. Be default is `auto` which will choose the best method to get scroll coordinates.
* `:target` - Specifies element to apply Scrollspy plugin.
* Html attributes - all w3c confirm html attributes for div's can be set via options and will be added to the surrounding scrollspy div.

## Examples

### Example 1: Scrollspy with list-group

```ruby
bs_row class: "m-3" do
  bs_col lg: 4 do
    bs_list_group id: "list-example", class: "mb-5", actionable_items: true, items: [
      { type: :link, text: "Item 1", path: "#list-item1"},
      { type: :link, text: "Item 2", path: "#list-item2" }
    ]
  end
  bs_col lg: 8 do
    bs_scrollspy target: "#list-example", offset: 0, height: 200 do
      h2 "Item 1", id: "list-item1"
      100.times do
        paragraph "Text for item 1"
      end
      h2 "Item 2", id: "list-item2"
      100.times do
        paragraph "Text for item 2"
      end
    end
  end
end
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.matestack.io/matestack-ui-bootstrap/2.1/api/components/scrollspy.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
