1

The javascript project I am working on is trying to incorporate a 'scroll-to-top' button that only renders after scrolling down (y-axis) 20px inside a Vuetify v-dialog component. We also have a v-card and v-treeview (has scrollable list of items) inside of the v-dialog. However, I can't seem to figure out how to actually 'grab' the scroll event within that v-dialog component to trigger anything.

<v-dialog>
  <v-card>
    <v-treeview>  //scrollable list
    </v-treeview>
  </v-card>
</v-dialog>

Any thoughts??

Here is a very similar Codepen of what I am trying to accomplish. https://codepen.io/carlos-henreis/pen/vzXKBJ

Thanks!

7
  • Looks like you forgot to add the link Commented Nov 27, 2020 at 20:07
  • @DavidGo thanks for catching that! Commented Nov 27, 2020 at 22:10
  • So, you've tried to place @scroll event on the dialog, right? Commented Nov 28, 2020 at 7:41
  • And did you add scrolable prop? vuetifyjs.com/components/dialogs#scrollable Commented Nov 28, 2020 at 7:59
  • I did try those. Honestly, because the v-treeview is inside a v-card, that is inside a v-dialog, I'm not even sure which component is the one that is actually scrolled. I've tried adding a scroll event, and the v-scroll directive, on all of them and I can't get any scroll event to even trigger anything. The codePen example works perfectly as a stand-alone component tossed into the root-level of any page view, because it can be triggered by the DOM window event, but I just can't access any 'scroll' event from inside a Vuetify component. Commented Nov 29, 2020 at 20:02

3 Answers 3

1

I experienced the same issue as OP. None of the expected behavior for v-scroll or $vuetify.goTo() occurred within the dialog.

Ultimately, I implemented a vanilla javascript solution by utilizing

element.scrollIntoView() - MDN

on an added div within the dialog.

In template:

<v-dialog>
  <div id="thisElement">
    <v-card>
      <v-treeview>
         //scrollable list
         <v-btn @click="goToTop">Scroll Up</v-btn>
      </v-treeview>
    </v-card>
  </div>
</v-dialog>

In methods:

goToTop() {
    document.getElementByID("thisElement").scrollIntoView();
  },
Sign up to request clarification or add additional context in comments.

2 Comments

They're asking for the event that triggers when the view is being scrolled. So that they can trigger behaviour when the scrolling started. Your answer doesn't show how that is being done, I believe.
True, I was unfortunately unable to identify the event in dialog because it didn't occur within the dialog and instead would only occur at the document level. It is likely due to the fact that the dialog is removed from the normal document flow.
0
  • add "scrollable" prop to "<v-card>"

  • add v-scroll.self="onScroll" to (or element that's scrolling) (per v-scroll documentation)

  • add id to (id="requestform") (to select for scrolltop)

  • add button to scroll to top (same as codepen above)

  • add toTop method:

    toTop() {
      document.getElementById('requestform').scrollTop = 0
    },
    

Comments

0

If you want to have smooth transition:

document.getElementById("elementId").scrollIntoView({behavior: 'smooth'});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.