@egjs/conveyer
Version:
Conveyer adds Drag gestures to your Native Scroll.
127 lines (117 loc) • 2.83 kB
HTML
<style>
body {
background: #F0F3FB;
margin-left: 0;
margin-right: 0;
}
.items {
position: relative;
overflow: scroll hidden;
width: 100%;
white-space: nowrap;
overscroll-behavior: none;
user-select: none;
}
.container {
display: block;
position: relative;
width: 100%;
}
.item {
display: inline-block;
overflow: hidden;
margin: 18px 12px 30px 0;
width: 271px;
height: 244px;
line-height: 244px;
text-align: center;
font-weight: bold;
font-size: 40px;
border-radius: 3px;
background-color: #fff;
-webkit-box-shadow: 0 2px 2px 0 rgb(0 0 0 / 4%), 0 0 2px 0 rgb(0 0 0 / 15%);
box-shadow: 0 2px 2px 0 rgb(0 0 0 / 4%), 0 0 2px 0 rgb(0 0 0 / 15%);
}
#prev,
#next {
position: absolute;
top: 0;
z-index: 10;
}
#prev {
left: 100px;
}
#next {
right: 100px;
}
</style>
<body>
<button id="prev">PREV</button>
<button id="next">NEXT</button>
<div class="items">
<!-- <div class="container"> -->
<div class="item"><a href="#1">1</a></div>
<div class="item"><a href="#2">2</a></div>
<div class="item"><a href="#3">3</a></div>
<div class="item"><a href="#4">4</a></div>
<div class="item"><a href="#5">5</a></div>
<div class="item"><a href="#6">6</a></div>
<div class="item"><a href="#7">7</a></div>
<div class="item"><a href="#8">8</a></div>
<div class="item"><a href="#9">9</a></div>
<div class="item"><a href="#10">10</a></div>
<div class="item"><a href="#11">11</a></div>
<div class="item"><a href="#12">12</a></div>
<!-- </div> -->
</div>
</body>
<script src="../../dist/conveyer.js"></script>
<script>
const conveyer = new Conveyer(".items", {
preventClickOnDrag: true,
useSideWheel: true,
autoInit: false,
});
conveyer.on("reachStart", () => {
prev.disabled = true;
});
conveyer.on("leaveStart", () => {
prev.disabled = false;
});
conveyer.on("reachEnd", () => {
next.disabled = true;
});
conveyer.on("leaveEnd", () => {
next.disabled = false;
});
conveyer.on("finishScroll", (e) => {
console.log("finish", e);
})
next.addEventListener("click", () => {
// end to start
conveyer.scrollIntoView("end", {
excludeStand: true,
align: "start",
duration: 500,
offset: 0,
});
});
prev.addEventListener("click", () => {
// start to end
conveyer.scrollIntoView("start", {
excludeStand: true,
align: "end",
duration: 500,
offset: 0,
});
});
conveyer.init();
document.querySelectorAll(".item").forEach(el => {
el.addEventListener("click", () => {
conveyer.scrollIntoView(el, {
align: "center",
duration: 500,
});
});
});
</script>