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

How to make a Gallery? #18

Open
9mm opened this issue Oct 13, 2022 · 0 comments
Open

How to make a Gallery? #18

9mm opened this issue Oct 13, 2022 · 0 comments

Comments

@9mm
Copy link

9mm commented Oct 13, 2022

I'm trying to make a swipe gallery with multiple images:

  <div class="gallery">
    <div ref="anchor" class="gallery-images" :style="{width: `${screenWidth * 6}px`}">
      <img v-for="image in images" :key="image" :src="require(`@/assets/images/${image}`)" :style="{width: `${screenWidth}px`}">
    </div>
  </div>

JS:

  setup() {
    // TODO dynamically change
    const screenWidth = ref(375);

    const anchor = ref();

    const { motionProperties } = useMotionProperties(anchor, {
      cursor: 'grab',
      x: 0,
      y: 0,
    });

    const { set } = useSpring(motionProperties);

    const dragHandler = ({ movement: [x], dragging }) => {
      if (!dragging) {
        set({ x: 0, y: 0, cursor: 'grab' });
        return;
      }

      set({ x, y: 0, cursor: 'grabbing' });
    };

    useDrag(dragHandler, {
      domTarget: anchor,
    });

    return {
      anchor,
      screenWidth,
    };
  },

CSS

.gallery {
  @apply overflow-x-hidden;
}
.gallery-images {
  @apply flex flex-row justify-start items-start;
}

It works fine on mobile but on desktop, I can see it changing the cursor and attempting to change the translateZ (it changes for 1ms and changes back to zero), from there it just stays zero and on desktop it wont drag.

If I use incognito device emulation and make the device very large, same as regular desktop, it DOES work, so maybe it has to do with gestures / mouse not being 1:1 consistent?

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

1 participant