Home > Back-end >  Image shuffling, realize the current picture before a, after a
Image shuffling, realize the current picture before a, after a

Time:09-18

I wrote js, I want is that the effect of a few image shuffling, press the button to the left, changes to the current picture on one piece, press the button to the right to change the current image of the next, but I now realize is that the effect of the first press the forward button in the array of the first, the second press is the second in the array, could you tell me how to modify to achieve what I want?

Window. The onl oad=function () {
SetInterval (' ChangeImg () ', 1500); }
Var I=1;
The function ChangeImg () {I +=1; Document. The getElementById (" img "). The SRC='https://bbs.csdn.net/topics/image/img' + I + 'JPG'; If (I==7) {I=0; }}
</script>
Var imgArr=[" images/img1. JPG ", "image/img2. JPG", "image/img3. JPG", "image/img4. JPG", "image/img5. JPG",, "image/img6. JPG", "image/img7. JPG"].
Var index=0;
The function next () {document. GetElementById (" img "). src=https://bbs.csdn.net/topics/imgArr [index];
Index++;
If (index==imgArr. Length) {index=0; }}
The function back () {document. GetElementById (" img "). The SRC=https://bbs.csdn.net/topics/imgArr [index];
The index -;
If (index<0 {index=imgArr. Length - 1; }}
</script>

CodePudding user response:

 
Var imgArr=[" images/img1. JPG ", "image/img2. JPG", "image/img3. JPG", "image/img4. JPG", "image/img5. JPG", "image/img6. JPG", "image/img7. JPG"].
Var index=0;
The function next () {
Index++;
If (index==imgArr. Length) {
The index=0;
}
Document. The getElementById (" img "). The SRC=https://bbs.csdn.net/topics/imgArr [index];
}
The function back () {
index--;
If (index & lt; 0 {
index=imgArr.length - 1;
}
Document. The getElementById (" img "). The SRC=https://bbs.csdn.net/topics/imgArr [index];
}
</script>

Document. The getElementById (" img "). The SRC=https://bbs.csdn.net/topics/imgArr [index]; You should be placed behind the index after the change, and you define an array has a problem, I can't see two commas together

CodePudding user response:

With front frame,
  • Related