Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe from Right to Left to open Drawer

Tags:

javascript

css

I have created a fork of this cool swipe drawer navigation: https://codepen.io/carl-victor-fontanos/pen/NQPLGW which works perfectly when swiping from Left to Right.

I am currently attempting to enable swiping from Right to Left, but I was only able to get it partially working. Here is what I've got so far: https://codepen.io/carl-victor-fontanos/pen/gVbdYq -- in this pen you will notice that it now opens from Right to Left, but the problem is that the swipe is still in reverse which is not what I want. I have modified the CSS to get the position to appear in right instead of left, and in the Javascript side I have changed translateX from negative to positive value.

Hopefully someone can help me get this working, as I have been trying to solve this for hours.

like image 606
Carl Avatar asked Oct 16 '22 12:10

Carl


1 Answers

The actual simple fix for the swipe direction is to set x = -x in the "move" function

    function move(x, e) {
      x = -x;  

We could have a cleaner solution but this works. Then I think you need to change the intent calculation because with just the x =-x change you need to swipe slowly until the edge to actually close the panel. Hope this helps

(I just realised I just checked the closing not the opening).

like image 100
Yoann Maingon Avatar answered Oct 19 '22 11:10

Yoann Maingon