PHP Classes

File: frontend/js/componentes/carousel.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Micro-Blog   frontend/js/componentes/carousel.js   Download  
File: frontend/js/componentes/carousel.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Micro-Blog
Blog management system extensible with classes
Author: By
Last change:
Date: 2 days ago
Size: 2,023 bytes
 

Contents

Class file image Download
export const Carousel = { template: ` <div v-if="imagens.length > 0" class="carousel-container"> <div class="carousel-slide"> <img :src="imagens[slideAtual]" alt="Slide imagem" /> </div> <div class="carousel-indicators"> <button v-for="(imagem, index) in imagens" :key="index" @click="mudarSlide(index)" :class="{'active': index === slideAtual}"> </button> </div> </div> `, data() { return { imagens: [], slideAtual: 1, totalImagens: 0 }; }, beforeMount(){ this.contaArquivos(); }, created() { this.iniciarTimer(); }, inject: ['urlBase'], methods: { contaArquivos() { fetch(`../../img/conta.php`) .then(response => response.json()) .then(data => { this.totalImagens = data.total; this.carregarImagens(); }) .catch(error => console.error('Erro ao contar imagens:', error)); }, carregarImagens() { for (let i = 1; i <= this.totalImagens; i++) { const imgPath = `./img/slide/slide${i}.webp`; this.verificarImagemExiste(imgPath, (existe) => { if (existe) { this.imagens.push(imgPath); } }); } }, verificarImagemExiste(url, callback) { const img = new Image(); img.onload = () => callback(true); img.onerror = () => callback(false); img.src = url; }, mudarSlide(index) { this.slideAtual = index; }, iniciarTimer() { setInterval(() => { this.slideAtual = (this.slideAtual + 1) % this.imagens.length; }, 6000); } } };