# Trigger Dash Callback from scroll (overflow div)

**URL:** <https://community.plotly.com/t/trigger-dash-callback-from-scroll-overflow-div/74658>\
**Category:** Dash Python\
**Created:** [April 22, 2023, 11:15am UTC](https://community.plotly.com/t/trigger-dash-callback-from-scroll-overflow-div/74658 "2023-04-22T11:15:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Louis](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Louis](https://community.plotly.com/u/Louis)\
**Post date:** [April 22, 2023, 2:46pm UTC](https://community.plotly.com/t/trigger-dash-callback-from-scroll-overflow-div/74658/3 "2023-04-22T14:46:40Z")

</div>

Thank you so much, it actually worked. Nowhere I found a solution to triggering a Dash Callback from Javascript.  
Here is the full solution:

```auto
#add virtualization based on scroll
@app.callback(
    Output('table', 'n_clicks'),
    Input('scrollpos', 'children')
)
def virtualization_table(scroll):
    print("scroll:")
    print(scroll)
    return None

app.clientside_callback(
    """
    function(n) {
        var obj = document.getElementById('scrollpos');
        var scrollpos = obj.innerHTML;
        console.log('scrollpos: ' ,scrollpos)
        console.log('n_clicks:', n)
        return scrollpos;
    }
    """,
    Output('scrollpos', 'children'),
    Input('scroll_btn', 'n_clicks')
)

```

and in the js file:

```auto
const checkElement = async selector => {
    while ( document.querySelector(selector) === null) {
        await new Promise( resolve => requestAnimationFrame(resolve) )
    }
    return document.querySelector(selector);
};

checkElement('#table').then((selector) => {
  console.log(selector);
  var obj = document.getElementById('scrollpos');
  selector.addEventListener('scroll', function() {
    obj.innerHTML = selector.scrollTop
    console.log('Current scroll value: ', selector.scrollTop);
    
    document.getElementById('scroll_btn').click(); // trigger click event on hidden button
  });
});

```

---

_[View the full topic](https://community.plotly.com/t/trigger-dash-callback-from-scroll-overflow-div/74658)._
