Skip to content

Commit

Permalink
adicionado javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCastro86 committed Oct 1, 2024
1 parent bb514cd commit b844f80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
28 changes: 1 addition & 27 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,7 @@ <h4>Condomínio Residencial dos Lagos</h4>
<p>&copy; 2024 Robert Castro Imóveis & Cia. Todos os direitos reservados. CRECI: 214.037-F</p>
</footer>

<script>
document.addEventListener('DOMContentLoaded', function () {
const carrosseis = document.querySelectorAll('.carrossel');

carrosseis.forEach(carrossel => {
const imgs = carrossel.querySelectorAll('img');
const prevBtn = carrossel.querySelector('.prev');
const nextBtn = carrossel.querySelector('.next');
let currentIndex = 0;

function showImage(index) {
imgs.forEach(img => img.classList.remove('active'));
imgs[index].classList.add('active');
}

prevBtn.addEventListener('click', () => {
currentIndex = (currentIndex - 1 + imgs.length) % imgs.length;
showImage(currentIndex);
});

nextBtn.addEventListener('click', () => {
currentIndex = (currentIndex + 1) % imgs.length;
showImage(currentIndex);
});
});
});
</script>
<script type="text/javascript" src="index.js"></script>
</body>

</html>
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
document.addEventListener('DOMContentLoaded', function () {
const carrosseis = document.querySelectorAll('.carrossel');

carrosseis.forEach(carrossel => {
const imgs = carrossel.querySelectorAll('img');
const prevBtn = carrossel.querySelector('.prev');
const nextBtn = carrossel.querySelector('.next');
let currentIndex = 0;

function showImage(index) {
imgs.forEach(img => img.classList.remove('active'));
imgs[index].classList.add('active');
}

prevBtn.addEventListener('click', () => {
currentIndex = (currentIndex - 1 + imgs.length) % imgs.length;
showImage(currentIndex);
});

nextBtn.addEventListener('click', () => {
currentIndex = (currentIndex + 1) % imgs.length;
showImage(currentIndex);
});
});
});

0 comments on commit b844f80

Please sign in to comment.