I have a series of equally sized boxes inside a container with absolute positioning, where the total width of the container equals boxWidth * n. This container is within a relative positioned parent container with overflow hidden, spanning multiple rows. When swiping left or right, the horizontal position of the box container adjusts by 1 boxWidth in the corresponding direction, ensuring it stays within bounds of (0, 0) and ((boxWidth * n), 0).
This represents a simplified version of my current setup, which functions well. However, if two swipes occur before the CSS transition completes, the incorrect 'current' position is referenced. How can I address this issue?
HTML
<div class="widget a">
<div class="overflow">
...
</div>
</div>
...
CSS
* {
margin:0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.widget {
width: 200px;
position: relative;
height: 100px;
overflow: hidden;
}
.overflow {
transition: all 0.5s ease-out;
-o-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;
-webkit-transition: all 0.5s ease-out;
height: 100px;
position:absolute;
left: 0;
}
.box {
user-select: none;
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
float: left;
...
}
.box:hover{
cursor:pointer;
}
JS
var fullbox = '200',
overflows = [$('.a .overflow'), $('.b .overflow'), $('.c .overflow'), $('.d .overflow')];
// Set Widths of Overflow Boxes
for (var i=0; i < 4; i++){
overflows[i].width(overflows[i].children().length * fullbox);
}
// Swipe Handlers
$('.overflow').on({
swipeleft: function () {
if ($(this).position().left != '-' + ($(this).children().length - 1) * fullbox) {
$(this).css('left', '-=' + fullbox);
}
},
swiperight: function () {
if ($(this).position().left !== 0) {
$(this).css('left', '+=' + fullbox);
}
}
});