Jump to content
Search Community

Set start position of Draggable when using type "scroll"

dt_roger test
Moderator Tag

Go to solution Solved by dt_roger,

Recommended Posts

I have a Vue app with a timeline that can be scrolled both horizontal and vertical with Draggable using type="scroll".

      Draggable.create(this.$refs.lo_sectionList, {
        type: "scroll",
        dragClickables: true,
        lockAxis: false,
        zIndexBoost: false,
        onDrag: this.onTimelineDrag,
      });
 

 

When the user clicks one of the buttons on the timeline, a new page is opened. When the user then goes back to the timeline it is positioned at the beginning, not the position it had when the user clicked the button. 

 

To fix this I am storing the scrollLeft value in a global variable when a button is clicked, but I am unable to find out how to set the timeline position when initiating the draggable.

 

Does anyone have any suggestions on how to do it?

 

 

 

Link to comment
Share on other sites

  • Solution

Thank you for your answer, Jack.

 

I don't have a timeline, just the Draggable. 

 

I solved the problem by setting scrollLeft of the element after initiating Draggable. I can swear this did not work when I tried it last night, but there you go... The dangers of late night programming, I guess 🙄

 

The solution is like this (in the mounted lifecycle method)

 

 
      Draggable.create(this.$refs.lo_sectionList, {
        type: "scroll",
        dragClickables: true,
        lockAxis: false,
        zIndexBoost: false,
        onDrag: this.onTimelineDrag,
      });
    // * Set scroll left to the stored position
    this.$refs.lo_sectionList.scrollLeft = this.globalVars.timelineScroll;

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...