Sorry for answering late. The widgets in the pagebuilder are loaded in the background, so javascript that is added to the bottom of the layout may not be able to find the html elements inside the widgets. You can insert a conditional script in the pagebuilder to initialize your javascript carousel.
You can do something like this in your widget view:
@{
// EnsureStartsWithLetter is our custom HTML ID generator method.
var carouselGuid = Guid.NewGuid().EnsureStartsWithLetter();
}
<div id="@carouselGuid">
<!-- Your html -->
</div>
@{
if (Context.Kentico().PageBuilder().EditMode)
{
<script>
var carousel = document.getElementById('@carouselGuid');
var intialisedCarousel = new Swiper(carousel, {
loop: false,
});
</script>
}
}