所以我正在制作这个健身应用程序,而且我对hammer.js相当新。所以我制作了这段代码:
var element = document.getElementById('swipe');
var trainings = new Array();
trainings = ["Cross Trainer", "Push ups", "Plank"];
var header = document.getElementById('title');
Hammer(element).on('panright', function(event){
var training = trainings[0];
if(header.innerHTML != training) {
header.innerHTML = training;
if (training == "Cross Trainer") {
element.innerHTML = "10 min";
} else if (training == "Push ups") {
element.innerHTML = "2 x 10 Wiederholungen";
} else if (training == "Plank") {
element.innerHTML = "2 x 10 Wiederholungen";
}
trainings.shift();
trainings.push(training);
}
});
这是一个测试,我想要通过练习轻扫,所以我使用了panright。它有效,但该函数被多次调用。
如何防止此行为?
谢谢!