需求:京東商品頁式圖片左右滑動,無滾動條、手指跟隨順滑、釋放自動吸附。原生 overflow-x:auto 會出現滾動條;手寫 touchmove 位移難以實現慣性與邊界彈性。
new Flipsnap('.carousel').carousel {
overflow: hidden; /* 關鍵:隱藏滾動條 */
white-space: nowrap;
font-size: 0; /* 消除 inline-block 間隙 */
}
.item {
display: inline-block;
width: 100%; /* 或固定寬度 */
white-space: normal;
font-size: 16px;
}
touchstart 記錄座標,touchend 判斷位移閾值requestAnimationFrame 實現減速曲線transform 需 will-change、GPU 加速Swiper、iSlider、better-scroll 均成熟可用,按項目依賴體積選型。