Javascript jquery-滑动页面计数

Javascript jquery-滑动页面计数,javascript,jquery,html,swipe,Javascript,Jquery,Html,Swipe,我正在使用库touchwipe.js创建一个滑动页面系统 使用我现有的方法,我可以在页面之间交换,但是,我无法正确地返回到上一页 现在,如果我左右滑动几次,计数系统就会将滑动相加。 如何使计数系统正确地在页面之间移动 var swipeRight = 0; var swipeLeft = 0; var swipePage = 0; function swipe1(event, direction, distance, duration, fingerCount) { if (direct

我正在使用库touchwipe.js创建一个滑动页面系统

使用我现有的方法,我可以在页面之间交换,但是,我无法正确地返回到上一页

现在,如果我左右滑动几次,计数系统就会将滑动相加。 如何使计数系统正确地在页面之间移动

var swipeRight = 0;
var swipeLeft = 0;
var swipePage = 0;

function swipe1(event, direction, distance, duration, fingerCount) {

  if (direction == "left") {
    swipeLeft++;
    if (swipeLeft == 5) {
      swipeLeft = 0;
    }
  }

  if (direction == "right") {
    swipeRight++;
    if (swipeRight == 5) {
      swipeRight = 0;
    }
  }

  swipePage = swipeLeft - swipeRight;

  if (swipePage == 0) {
    $("html, body").animate({
      scrollLeft: 0,
    }, 1500);
    swipeLeft = 0;
    swipeRight = 0;
  }

  if (swipePage == 1) {
    $("html, body").animate({
      scrollLeft: $("#hwwPage").offset().left
    }, 1500);
  }

  if (swipePage == 2) {
    $("html, body").animate({
      scrollLeft: $("#projPage").offset().left
    }, 1500);
  }

  if (swipePage == 3) {
    $("html, body").animate({
      scrollLeft: $("#digiPage").offset().left
    }, 1500);
  }

  if (swipePage == 4) {
    $("html, body").animate({
      scrollLeft: $("#contPage").offset().left
    }, 1500);
  }

  console.log(swipeRight + "+" + swipeLeft);
  console.log(swipePage);
}

我已经修改了你的代码:我想你并不需要swipeleft和swiperight。只需根据滑动方向增加或减少滑动值:

var swipePage = 0;

function swipe1(event, direction, distance, duration, fingerCount) {

    if (direction == "left") 
        if (swipePage > 0) 
           swipePage++;

    if (direction == "right") 
        if (swipePage < 4) 
           swipePage--;

    var pageIds = ["",
                   "#hwwPage",
                   "#projPage",
                   "#digiPage",
                   "#contPage"
                  ];
    $("html, body").animate({
       scrollLeft: $(pageIds[swipePage]).offset().left
    }, 1500);
}
var swipePage=0;
功能swipe1(事件、方向、距离、持续时间、手指计数){
如果(方向=“左”)
如果(swipePage>0)
swipePage++;
如果(方向=“右”)
如果(swipePage<4)
swipePage--;
var pageIds=[“”,
“#hwpage”,
“#项目页面”,
“#数字化”,
“#续页”
];
$(“html,body”).animate({
scrollLeft:$(PageID[swipePage]).offset().left
}, 1500);
}

答案对你有用吗?做了一些改动谢谢你Sid我现在不在电脑前。。我会在10分钟后报到谢谢,我已经尝试了你的代码,但是它显示了错误“SyntaxError:意外标记':'。在数组元素后面应该有一个结尾“]”或“,”。@SNos是的,愚蠢的错误。。我已经修好了。。但我想你昨天已经可以独自完成了;)