moveUp() { if(this.clickNum !== this.getInfo.list.length){ this.clickNum++ console.log(this.clickNum); // 判断是否需要平移 if(this.clickNum > this.getInfo.list.length-3){ }else{ console.log('应该执行平移'); this.clickCount-= 190; } }else{ } }, moveDown(){ if(this.clickNum >0 ){ this.clickNum-- if(this.clickCount < 0){ this.clickCount+= 190 }else{ } } },这两个函数中,moveUp是向上平移,moveDown是向下平移,现在moveUp里第一个条件被满足后,如果我执行moveDown方法小于3次,那么moveUp函数里的向上平移将不被执行,你修改一下,让moveUp的平移代码可以不被<3所限制,同时不动moveUp里的第二层if判断逻辑,把代码给我
时间: 2024-03-19 09:46:33 浏览: 17
可以将moveUp函数中的第一个if语句改为while循环,这样可以让向上平移的代码不被<3所限制,多次执行直到不满足条件为止。同时,需要增加一个计数器,在moveDown函数中每次执行时将计数器清零,当计数器达到3时再执行moveUp函数。修改后的代码如下:
```
let count = 0; // 新增计数器
moveUp() {
while (this.clickNum !== this.getInfo.list.length) {
this.clickNum++;
console.log(this.clickNum);
// 判断是否需要平移
if (this.clickNum > this.getInfo.list.length - 3) {
break;
} else {
console.log('应该执行平移');
this.clickCount -= 190;
}
}
}
moveDown() {
if (this.clickNum > 0) {
this.clickNum--;
count = 0; // 每次执行moveDown时清零计数器
if (this.clickCount < 0) {
this.clickCount += 190;
}
}
// 判断是否需要执行moveUp函数
if (count === 3) {
this.moveUp();
} else {
count++;
}
}
```
这样修改之后,moveUp函数中的向上平移代码就不会被<3所限制了,可以一直执行直到不满足条件为止。同时,增加了一个计数器,每次执行moveDown函数时将计数器清零,当计数器达到3时再执行moveUp函数。
相关推荐
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)