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

Router links triggers during slides draggin #46

Open
mcake8 opened this issue Jan 8, 2019 · 5 comments
Open

Router links triggers during slides draggin #46

mcake8 opened this issue Jan 8, 2019 · 5 comments

Comments

@mcake8
Copy link

mcake8 commented Jan 8, 2019

I have a slider with a router link inside each slide, and i can't swipe or drag slides on desktop without redirecting to another route. I guess it's because router links click can't be prevented.

@eertmanhidde
Copy link

I had the same issue. Didn't solved it on a very clean way but you can use the drag event to add a class when dragging. Then simply put pointer-events: none on that class.

flickity.on( 'dragMove', function( event, pointer, moveVector ) { $($projectItem).addClass('nopointer'); }); flickity.on( 'dragEnd', function( event, pointer ) { $($projectItem).removeClass('nopointer'); });

the class :

.nopointer { pointer-events: none; }

@mcake8
Copy link
Author

mcake8 commented Jan 20, 2019

The best way that i find is like this
mounted() { setTimeout(() => { this.$refs.flickity.on("staticClick", event => { this.$router.push( "/projects/" + event.target.dataset.id ); }); }, 100); },
im attaching event on mounted hook and get link's href from dataset of an element that had been clicked

@aliqasemzadeh
Copy link

@mcake8
Not work for me.

@ArashKenji73
Copy link

i have same problem
please fix this or give us onDrag event

@luksak
Copy link

luksak commented Apr 12, 2022

Here is a more generic version of @eertmanhidde 's approach:

mounted() {
  setTimeout(() => {
    const cells = this.$refs.flickity.getCellElements()
    this.$refs.flickity.on('dragMove', function (event, pointer, moveVector) {
      cells.forEach((element) => {
        element.classList.add('nopointer')
      })
    })
    this.$refs.flickity.on('dragEnd', function (event, pointer) {
      cells.forEach((element) => {
        element.classList.remove('nopointer')
      })
    })
  }, 100)
}

That works perfectly for me.

You'll still need this style:

.nopointer { pointer-events: none; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants