Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On scroll element also moves up and down?So can this feature not be used in a long page? #11

Open
ashutosh1807 opened this issue Jun 29, 2018 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@ashutosh1807
Copy link

No description provided.

@ashutosh1807
Copy link
Author

By element I mean draggable element

@IsraelZablianov
Copy link
Owner

Please provide explanation, example and screenshot

@ashutosh1807
Copy link
Author

See my draggable component gets attached to screen and remains there only as I scroll through the page ...for eg if I have element at centre of screen then it remains there only ..it doesn't get attached to page

@IsraelZablianov
Copy link
Owner

Currently you can't.
We are working on it

@lgXenos
Copy link

lgXenos commented Aug 22, 2018

The problem is actual for me too
Very sad...

@ashutosh1807 Are you fix this for you? Or what the alternative of yours solution?

@IsraelZablianov IsraelZablianov self-assigned this Sep 26, 2018
@IsraelZablianov IsraelZablianov added the bug Something isn't working label Sep 26, 2018
@Zearin
Copy link
Contributor

Zearin commented Nov 16, 2018

I was about to open this very issue, when I found that someone else ran into the same problem.


Source of this issue

The issue is with line 163 in draggable.ts, where the element’s position is set to fixed.

Recommendation

  • This line of code should probably replace fixed with absolute. I think most web developers assume this would be the default kind of positioning for draggable-type functionality.

  • Perhaps an arg parameter for the directive’s binding could allow client code to “opt-in” to the current behavior (via something like v-draggable:fixed) to declare a component should have the current “scroll-ignoring” positioning.

@tpaksu
Copy link
Contributor

tpaksu commented Mar 28, 2019

FYI, onPositionChange event also can be a workaround before the code itself isn't changed.

I'm using the directive like v-draggable='draggables' and then the data and event parameter would become:

data() {
    return {
        draggables: {
            onPositionChange: this.onPosChanged
        }
    };
},
methods: {
    onPosChanged: function(positionDiff, absolutePosition, event) {
        if(event.target.closest("[draggable-state]")){
            event.target.closest("[draggable-state]").style.position = "absolute";            
        }
    }
},

@tpaksu
Copy link
Contributor

tpaksu commented Mar 28, 2019

Or better;

[draggable-state]{
    position: absolute !important;
}

@IsraelZablianov
Copy link
Owner

Hi guys,
first of all thanks for your ideas, they are always welcomed.

I already started to work about the solution, 'absolute' positioning is problematic with bounding-rectangle feature.

@lita-jerry
Copy link

When can solve this issues?

@IsraelZablianov
Copy link
Owner

it will take a while

@MalkSof
Copy link

MalkSof commented Oct 30, 2019

@IsraelZablianov I congratulate you on the pack you created. Please fix this function.

@Clan-Utility
Copy link

I've ended with a solution without modifying the directive, assuming multiple boxes to drag, bounding to a container.

1) Set each box a class

.drag-box {
  position: absolute !important;
}
  1. Each box's initialPosition is set relative to container, e.g. { left: 0, top: 0 }

  2. in onDragStart, change the box's position to 'fixed' and make sure top & left are wrt to the viewport

    onDragStart: function(positionDiff, absolutePosition, event) {
      let box = event && event.target && event.target.closest('[draggable-state]')
      if (box) {
        // Get the model
        const id = box.id
        let found = this.boxes.find(b => b.id === id)

        if (found && !found.firstTouched) {
          // On the first touch, the directive's initialPosition, startDragPosition, currentDragPosition needs to be set wrt to the viewport
          const container = this.$refs.container.getBoundingClientRect()
          const top = absolutePosition.top + container.top
          const left = absolutePosition.left + container.left
          box.style.top = top + 'px'
          box.style.left = left + 'px'

          let draggableState = JSON.parse(box.getAttribute('draggable-state')) || {}
          draggableState.initialPosition = { left, top }
          draggableState.startDragPosition = { left, top }
          draggableState.currentDragPosition = { left, top }
          box.setAttribute('draggable-state', JSON.stringify(draggableState))

          // Record in model that the box has been touched
          found.firstTouched = true
        } else {
          box.style.top = absolutePosition.top + 'px'
          box.style.left = absolutePosition.left + 'px'
        }
        // Remove the class
        box.classList.remove('drag-box')
      }
    }
  1. in onDragEnd, change the box's position to 'absolute' and make sure top & left are wrt to the container
    onDragEnd: function(positionDiff, absolutePosition, event) {
      let box = event && event.target && event.target.closest('[draggable-state]')
      if (box) {
        const container = this.$refs.container.getBoundingClientRect()
        const top = absolutePosition.top - container.top
        const left = absolutePosition.left - container.left
        box.style.top = top + 'px'
        box.style.left = left + 'px'

        // Add the class again
        box.classList.add('drag-box')
      }
    }

@Clan-Utility
Copy link

A remaining problem is if the page scrolled, the directive's initialPosition, startDragPosition, currentDragPosition are not updated and the first touch of the box will suddenly move the box to somewhere else. But after the first touch, everything is fine again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants