Skip to content

how can I trigger select event when I use infinte viewer #179

@DoubleCorner

Description

@DoubleCorner

when scroll is triggered, I add data to list, but seleto not trigger select event @arturovt. Look forward to your reply.

<script setup>
import InfiniteViewer from "vue3-infinite-viewer";
import Selecto from "vue3-selecto";
import { nextTick, ref } from "vue";
const hitRate = 0;
const selectByClick = true;
const selectFromInside = false;
const toggleContinueSelect = ["shift"];
const ratio = 0;
const viewerRef = ref(null);
const selectoRef = ref(null);
const cubes = ref([]);
for (let i = 0; i < 30 * 7; ++i) {
  cubes.value.push(i);
}
const onClick = () => {
  viewerRef.value.scrollTo(0, 0);
};
const onDragStart = (e) => {
  if (e.inputEvent.target.nodeName === "BUTTON") {
    return false;
  }
  return true;
};
const onSelect = (e) => {
  e.added.forEach((el) => {
    el.classList.add("selected");
  });
  e.removed.forEach((el) => {
    el.classList.remove("selected");
  });
};
const onScroll = ({ direction }) => {
  for (let i = 0; i < 30 * 7; ++i) {
    cubes.value.push(i);
  }
  viewerRef.value.scrollBy(direction[0] * 10, direction[1] * 10);
};
const onScroll$0 = () => {
  selectoRef.value.checkScroll();
};
</script>
<template>
  <div class="app">
    <div class="container">
      <div class="logos logo" id="logo">
        <a href="https://github.com/daybrush/selecto" target="_blank">
          <img
            src="https://daybrush.com/selecto/images/256x256.png"
            class="selecto"
          />
        </a>
        <a href="https://github.com/daybrush/infinite-viewer" target="_blank">
          <img src="https://daybrush.com/infinite-viewer/images/logo.png" />
        </a>
      </div>
      <h1>Select in the Infinite Scroll Viewer.</h1>
      <p class="description">
        Selecting the scroll area area causes scrolling.
      </p>
      <button class="button" @click="onClick">Reset Scroll</button>
      <Selecto
        ref="selectoRef"
        :dragContainer="'.elements'"
        :selectableTargets="[
          '#selecto1 .cube',
          '#selecto2 .element',
          '#selecto3 li',
        ]"
        @dragStart="onDragStart"
        @select="onSelect"
        @scroll="onScroll"
        :scrollOptions="{
          container: '.infinite-viewer',
          getScrollPosition: () => {
            return [viewerRef.getScrollLeft(), viewerRef.getScrollTop()];
          },
          throttleTime: 30,
          threshold: 0,
        }"
        :hitRate="hitRate"
        :selectByClick="selectByClick"
        :selectFromInside="selectFromInside"
        :toggleContinueSelect="toggleContinueSelect"
        :ratio="ratio"
      ></Selecto>
      <InfiniteViewer
        className="elements infinite-viewer"
        ref="viewerRef"
        @scroll="onScroll$0"
      >
        <div class="viewport selecto-area" id="selecto1">
          <div class="cube" :key="i" v-for="i in cubes"></div>
        </div>
      </InfiniteViewer>
      <div class="empty elements"></div>
    </div>
  </div>
</template>

<style>
html,
body,
#root {
  position: relative;
  margin: 0;
  padding: 0;
  height: 100%;
  color: #333;
  background: #fdfdfd;
}

.app {
  position: relative;
  min-height: 100%;
  padding: 10px 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.container {
  max-width: 800px;
}

body {
  background: #fff;
}

.logo {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 0px auto;
  font-size: 0;
  text-align: left;
}

.logo.logos {
  width: 320px;
  text-align: center;
}

.logos .selecto {
  padding: 16px;
}

.logo img {
  position: relative;
  height: 100%;
  box-sizing: border-box;
}

.cube {
  display: inline-block;
  border-radius: 5px;
  width: 40px;
  height: 40px;
  margin: 4px;
  background: #eee;
  --color: #4af;
  line-height: 40px;
}

h1,
.description {
  text-align: center;
}

.button {
  border: 1px solid #333;
  color: #333;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  cursor: pointer;
  width: 120px;
  height: 42px;
  font-size: 14px;
  letter-spacing: 1px;
  transition: all ease 0.2s;
  margin: 0px 5px;
}

.button:hover {
  background: #333;
  color: white;
}

.elements {
  margin-top: 40px;
  border: 2px solid #eee;
}

.selecto-area {
  padding: 20px;
}

#selecto1 .cube {
  transition: all ease 0.2s;
}

.moveable #selecto1 .cube {
  transition: none;
}

.selecto-area .selected {
  color: #fff;
  background: var(--color);
}

.scroll {
  overflow: auto;
  padding-top: 10px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.infinite-viewer,
.scroll {
  width: 100%;
  height: 300px;
  box-sizing: border-box;
}

.infinite-viewer .viewport {
  padding-top: 10px;
}

.empty.elements {
  border: none;
}

.correct {
  position: relative;
  padding: 20px;
  text-align: center;
  margin: auto;
  width: 100%;
}
.correct .target {
  position: relative;
  width: 100px;
  height: 100px;
  color: #fff;
  margin: 10px 20px;
  line-height: 100px;
  text-align: center;
  display: inline-block;
}
.correct svg {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0.9;
  transform: translateZ(0px);
}
.correct svg path {
  stroke: #333;
  stroke-width: 2;
  fill: transparent;
}
</style>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions