N
N
Nikita Kit2018-02-27 14:38:39
JavaScript
Nikita Kit, 2018-02-27 14:38:39

Why doesn't the second callback on scroll work?

Given: A
page where all the scrollbars are customized with the simplebar plugin. According to the docs, in order to subscribe to a scroll, you need to hang up a listener on the element returned by the simplebar.getScrollElement() function.

There is a table on the page that scrolls horizontally at non-wide resolutions.

Needed:
Simulate the behavior of the position sticky header so that the header is friendly with the horizontal scrolling of the table.

What's wrong:
At resolutions without a horizontal table scrollbar, everything works well. I subscribed to the document scroll, stuck a header with the necessary styles and everything is ok. But when there is a horizontal scrollbar, the header remains fixed on the window and does not blend with the table. To synchronize it, I decided to subscribe to the horizontal scrollbar of the table, just like the scroll of the entire page

. Everything works as it should. fix and stick work out at the right time

scrollNode.scroll (e) ->
      hOffTop = header.offset().top - headerHeight
      if hOffTop <= 0
        lastScrollPoint = header.parents("div:first").offset().top - headerHeight
        stickHead.fix(header, {
          offset: headerHeight,
          event: e
          })
      if lastScrollPoint > 0
        stickHead.stick(header)


This is part of the code in stickHead.fix() - here I want to subscribe to the horizontal scrollbar. I find the one I need by checking the existence of the fix-head inside the scroll area and get the necessary element from it, I try to scroll horizontally, but console.log('scroll') is no longer executed.
if window.xScrollbars
        xScrollbars = window.xScrollbars
        xScrollbars.forEach (scrollbar, index) ->
          el = scrollbar.getScrollElement()

          posibleFixedHeader = $(el).find(selector)
          if posibleFixedHeader.length > 0
            console.log(el)
            el.addEventListener "scroll", (e) ->
              console.log('scroll')

do not understand why. What can be done in such a situation? Maybe there is some dynamic object in the DOM that changes when scrolling, whose changes can be subscribed to?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question