No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    scrollToElement with a fixed header

    Framework
    1
    2
    78
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sandroden
      sandroden last edited by

      Hi,

      I’m trying to setup a page with a scrollToElement . I have not really understood how I should prepare the parent. I managed to obtain a scrollToElement correctly working if the div with “scroll” class is the outer div in the content area.

      If I have a header (where I place the links that I’d like to stay visible) the scroll has a wrong offset.
      I prepared a codesandbox to show the two different situations.
      Which is the suggested solution for this kind of layout/request?

      thanks in advance
      Sandro

      sandroden 1 Reply Last reply Reply Quote 0
      • sandroden
        sandroden @sandroden last edited by sandroden

        I solved this by forcing the offset in the scrollToElement function. I subtract the offsetTop of the element that has the “scroll” class.
        So my final working function is:

        scrollToElement (el) {
          const target = getScrollTarget(el)
          const offset = el.offsetTop - target.offsetTop // adjust the scrolling
          const duration = 100
          setScrollPosition(target, offset, duration)
        }
        

        UPDATE: The adjustment (- target.offsetTop) is only needed if the scrollable element is not positioned. In that case el.offsetTop is referred to the offsetParent that is the closest positioned ancestor.

        1 Reply Last reply Reply Quote 1
        • First post
          Last post