【发布时间】:2019-06-07 18:45:31
【问题描述】:
我正在尝试制作一个通过水平拖动进行导航的图片库。我目前面临的问题是元素应该停止拖动时左右没有边界。我试过使用“容器”元素,但是当我这样做时,它会完全停止拖动。
我尝试使用“父级”或实际的 div 作为容器,但都没有正常工作。我在另一个留言板上看到,在这种情况下使用 flexbox 会使事情变得更加复杂,所以我转而使用 display: inline-block on images。
这是我目前的草稿:https://jsfiddle.net/samseurynck/ka1e9soj/21/
HTML
<div class="item_block_left">
<div class="item_block_left_gallery_container">
<div class="item_block_left_gallery">
<img class="item_block_left_gallery_item" src="https://placeimg.com/640/480/animals">
<img class="item_block_left_gallery_item" src="https://placeimg.com/200/200/animals">
<img class="item_block_left_gallery_item" src="https://placeimg.com/640/400/animals">
</div>
</div>
</div>
SCSS
.item_block_left{
height:200px;
width: 50%;
border: 1px solid pink;
overflow: hidden;
.item_block_left_gallery_container{
position: relative;
height:100%;
width: auto;
.item_block_left_gallery{
height:100%;
display: flex;
cursor: grab;
.item_block_left_gallery_item{
position: relative;
height:100%;
width:auto;
display: inline-block;
}
}
}
}
JQUERY
$(".item_block_left_gallery").draggable({
scroll: false,
axis: "x",
});
预期的结果是只能水平滚动/拖动图像,左侧或右侧没有空白。
【问题讨论】:
-
类似于物体碰撞检测,需要检测物品的左侧位置何时达到特定值。
标签: jquery-ui responsive-design flexbox draggable image-gallery