I have some list of div
elements ordered vertically. Using jQuery TouchSwipe plugin added swipe event to catch left-right swipe. Idea was to remove element from list by swiping it left or right side like this:
Finally I got something like this:
$(function() {
$('.swElement').swipe({
swipeStatus: function(event, phase, direction, distance, duration, fingerCount) {
console.log(distance);
if (phase == "move") {
if (direction == "right") {
$(this).css({
'right' : (distance*-1)+'px'
});
}
} else if (phase == "cancel") {
$(this).css({
'right' : 0
});
} else if (phase == "end") {
$(this).animate({
'right' : '-100%'
}, 200, function() {
$(this).remove();
});
} else {
//?????
}
},
threshold: 150,
maxTimeThreshold: 5000,
fingers: 'all'
});
});
.swElement {
display: block;
width: 100%;
height: 50px;
border: 1px solid black;
box-sizing: border-box;
padding: 0 10px;
line-height: 50px;
cursor: pointer;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/2130702/cdn/jquery.touchSwipe.min.js"></script>
<h2>Swipe right to remove element</h2>
<div class="swElement">Element</div>
<div class="swElement">Element</div>
<div class="swElement">Element</div>
<div class="swElement">Element</div>
<div class="swElement">Element</div>
Problem
It's working great on mobile chrome browser, but prevents up/down scroll on native android browser.
I understand that this swipeStatus
catch both left/right and up/dmown directions, but don't know how to prevent is from it - I need only right swipe event.
Any ideas? Thanks in advance.
Update
I can't use jQuery mobile framework, because it conflict's with other scripts which I have to use. Maybe there will be another way to figure out?