So I'm trying to do a simple back forward with a picture slider. I have gotten the next on the button, but need to create the function for back.
所以我试图用图片滑块做一个简单的后退。我已经在按钮上获得了下一个,但需要创建后退功能。
I cannot seem to get it and cannot remember with simple pure javascript. What would the if statement be? I assume the position needs to be changed to 0. Thank you for the advice.
我似乎无法得到它,也记不起简单的纯JavaScript。 if语句是什么?我认为这个职位需要改为0.谢谢你的建议。
For the forward I have:
对于前锋,我有:
function Forward()
xxxx[arrayPosition].className = "thumb";
mm[arrayPosition].className = "yyy";
if(arrayPosition == xxxx.length - 1){
arrayPosition = 0; }
else{
arrayPosition = arrayPosition + 1; in memory }
xxxx[arrayPosition].className = "thumb active";
mm[arrayPosition].className = "yyy active"; }
2 个解决方案
#1
0
When going back, you would want to check if the current arrayPosition
is 0
. If so, the array position should be updated to be the last index. For example:
返回时,您需要检查当前的arrayPosition是否为0.如果是,则应将阵列位置更新为最后一个索引。例如:
if(arrayPosition === 0) {
arrayPosition = xxxx.length - 1;
} else {
arrayPosition -= 1;
}
#2
0
try this
function Forward(){
xxxx[arrayPosition].className = "thumb";
mm[arrayPosition].className = "yyy";
if((arrayPosition == xxxx.length - 1)||
(arrayPosition == 0)){
arrayPosition = 0;
}else{
arrayPosition = arrayPosition + 1;
}
xxxx[arrayPosition].className = "thumb active";
mm[arrayPosition].className = "yyy active";
}
#1
0
When going back, you would want to check if the current arrayPosition
is 0
. If so, the array position should be updated to be the last index. For example:
返回时,您需要检查当前的arrayPosition是否为0.如果是,则应将阵列位置更新为最后一个索引。例如:
if(arrayPosition === 0) {
arrayPosition = xxxx.length - 1;
} else {
arrayPosition -= 1;
}
#2
0
try this
function Forward(){
xxxx[arrayPosition].className = "thumb";
mm[arrayPosition].className = "yyy";
if((arrayPosition == xxxx.length - 1)||
(arrayPosition == 0)){
arrayPosition = 0;
}else{
arrayPosition = arrayPosition + 1;
}
xxxx[arrayPosition].className = "thumb active";
mm[arrayPosition].className = "yyy active";
}