I want to make a video slider. The problem is that the loop works only one for each button, but the console.log keep working on click. The videos are generated in php with the vimeo api in a For loop.
When I first click on the right button, it works one time, and if I retry, it's dead. If I click on the left button after clicking on the right button, It will work one time but it skip one video and goes 2 video on the left.
The HTML in the web page after clicking on the right button then on the left one:
Here is my php code :
$CLIENT_IDENTIFIER = "{CLIENT_IDENTIFIER}";
$CLIENT_SECRET = "{CLIENT_SECRET}";
$ACCESS_TOKEN = "{ACCESS_TOKEN}";
$CLIENT_ID = "{CLIENT_ID}";
require 'vendor/autoload.php';
use Vimeo\Vimeo;
$client = new Vimeo($CLIENT_IDENTIFIER, $CLIENT_SECRET, $ACCESS_TOKEN);
$response = $client->request('/users/{CHANNEL}/videos?sort=date&direction=desc', array(), 'GET');
for ($i=0; $i < 7; $i++) {
$lien = $response["body"]["data"][$i]["uri"];
$video_id = substr($lien, 8);
echo '<div class="videos video-'.$i.'">
<iframe title="vimeo-player" src="https://player.vimeo.com/video/'.$video_id.'?" width="720" height="480" frameborder="0" allowfullscreen></iframe>
</div>';
}
Here is my JS code :
var videos = document.querySelectorAll(".videos");
next.addEventListener("click", function() {
for (let i=0; i<7; i++) {
videos[i].classList.remove("video"+[i]);
videos[i].classList.add("video"+[i-1]);
console.log(videos[i])
}
});
prev.addEventListener("click", function() {
for (let i=0; i<7; i++) {
videos[i].classList.remove("video"+[i]);
videos[i].classList.add("video"+[i+1]);
console.log(videos[i])
}
});
I don't know why it doesn't work, I hope you'll have a solution!