Act as a beginner webdeveloper not knowing much javascript, here is the HTML, CSS and…
- User
Act as a beginner webdeveloper not knowing much javascript, here is the HTML, CSS and Javascript Code for multi-item card slider, what i need is re-write javascript code such that the card keeps on sliding one at a time, doesn't stops at last, it should continue and then show card 1 on click next. Here are the codes : HTML :
</div> <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleProjects" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> </button> <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleProjects" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> </button> </div>CSS: @media (min-width: 768px) { .carousel-inner.projects { display: flex; } .carousel-item.projects { margin-right: 0; flex: 0 0 33.333333%; display: block; } } .carousel-inner.projects{ padding: 1em; } .card { margin: 0 .5em; box-shadow: 2px 6px 8px 0 rgba(22, 22, 26, 0.18); border: none; } .carousel-control-prev, .carousel-control-next{ background-color: #e1e1e1; width: 6vh; height: 6vh; border-radius: 50%; top: 50%; transform: translateY(-50%); }
and Javascript : var carouselWidth = (".carousel-item.projects").width(); var scrollPosition = 0;
- Assistant
Sure! To modify the carousel behavior so that it scrolls one card at a time without stopping at the last card and wraps around back to the first card, you can adjust the JavaScript code as follows:
- User
With these changes, the carousel will continually scroll one card at a time, it should not return to the first card after reaching the end, after end it should display card 1 but keeping intact card 2 to card 5, assuming card 6 is the end card.
- Assistant