I am using this peace of code https://github.com/ksloan/jquery-mobile-swipe-list that I have modified and its working fine. However the code has two buttons, right and left. In my project, I only have one in the right side so swipe left to uncover it its ok, but I cannot find how can I eliminate the swipe right since I dont have any button in the left side and it crashes every time it swipe that direction.
Any advice?
Code:
$(function() {
function prevent_default(e) {
e.preventDefault();
}
function disable_scroll() {
$(document).on('touchmove','#myPostsList .ui-content', prevent_default);
}
function enable_scroll() {
$(document).unbind('touchmove',' #myPostsList .ui-content', prevent_default);
}
var x;
$(document)
.on('touchstart', '.swipe-delete li > a', function(e) {
console.log(e.originalEvent.pageX);
///// GET ID OF SELECTED POST AND STORE IN A DIV FOR AJAX /////
document.getElementById("myPostIDStorage").value = $(this).attr('data-key');
$('.swipe-delete li > a.open').css('left', '0px').removeClass('open') ;// close em all
$(e.currentTarget).addClass('open');
x = e.originalEvent.targetTouches[0].pageX // anchor point
})
.on('touchmove', '.swipe-delete li > a', function(e) {
var change = e.originalEvent.targetTouches[0].pageX - x;
change = Math.min(Math.max(-100, change), 100); // restrict to -100px left, 0px right
e.currentTarget.style.left = change + 'px';
if (change < -10) disable_scroll() // disable scroll once we hit 10px horizontal slide
})
.on('touchend', '.swipe-delete li > a', function(e) {
var left = parseInt(e.currentTarget.style.left);
var new_left;
if (left < -35) {
new_left = '-100px';
} /*else if (left > 35) {
new_left = '100px'
} */ else {
new_left = '0px';
}
//e.currentTarget.style.left = new_left
$(e.currentTarget).animate({left: new_left}, 200)
enable_scroll();
});
});
Make sure you have all the Original code
All you need to do is change the Maths a little bit
where it says change = Math.min(Math.max(-100, change), 100);
change to change = Math.min(Math.max(-100, change), 0)
changing 100 to 0 means 0 pixels of movement from the left to right, so it doesn't move
Demo
if you wanted the right side to stop moving reverse the Math but this time 100 is plus number change = Math.min(Math.max(0, change), 100)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.