How to use js to call multiple collections in an array into a set of elements?
As shown in Figure: Click to switch three pictures at once
<div class="cright">
<div class="lbt" onclick="lbt()"><</div>
<div>
<img src="./imgs/1.1.webp" alt="">
<img src="./imgs/1.2.webp" alt="">
<img src="./imgs/1.3.webp" alt="">
</div>
<div class="rbt" onclick="rbt()">></div>
</div>
let arr1 = [
[
{ src: './imgs/1.1.webp', },
{ src: './imgs/1.2.webp', },
{ src: './imgs/1.3.webp', }
],
[
{ src: './imgs/1.4.webp', },
{ src: './imgs/1.5.webp', },
{ src: './imgs/1.6.webp', }
]
]
let index1=0
let lb2 = document.querySelectorAll('.cright img ')
lbt = function () {
index1--
if (index1 == -1) {
index1 = arr1.length - 1
}
//可行代码
lb2[0].src = arr1[index1][0].src
lb2[1].src = arr1[index1][1].src
lb2[2].src = arr1[index1][2].src
}
lb2[0].src = arr1[index1][0].src
lb2[1].src = arr1[index1][1].src
lb2[2].src = arr1[index1][2].src
This method can realize switching three pictures at a time, but it is still a little cumbersome and inconvenient, and the traversal method is not successful. Is there an easier way?
0 Answer
No answer yet
这家伙很懒,什么都没留下...