I am attempting to create a text animation around an oval shape, similar to the one shown below:
While I have found solutions for animating text in a circular pattern, I am experiencing issues when trying to adapt it for an oval shape.
Does anyone have any insight on how to achieve this effect? Your assistance would be greatly appreciated.
Here is the code snippet for creating the animation with a circle:
var radius = 200; // adjust to move items in and out
var fields = $('.carousel__item'),
container = $('.carousel'),
width = container.width(),
height = container.height();
var angle = 0,
step = (2 * Math.PI) / fields.length;
fields.each(function() {
var x = Math.round(width / 2 + radius * Math.cos(angle) - $(this).width() / 2);
var y = Math.round(height / 2 + radius * Math.sin(angle) - $(this).height() / 2);
if (window.console) {
console.log($(this).text(), x, y);
}
$(this).css({
left: x + 'px',
top: y + 'px'
});
angle += step;
});
.carousel {
width: 400px;
height: 400px;
margin: 10px auto;
position: relative;
border-radius: 50%;
animation: spin 60s linear infinite;
}
.carousel:hover {
animation-play-state: paused;
}
.carousel:hover .carousel__item {
animation-play-state: paused;
}
.carousel__item {
text-align: center;
width: 300px;
position: absolute;
animation: spin 60s linear infinite reverse;
font-size: 1.4rem;
}
@keyframes spin {
100% {
transform: rotate(1turn);
}
}
.carousel__item:hover {
animation-play-state: paused;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="carousel">
<div class="carousel__item">TEXTTEXTTEXT</div>
<div class="carousel__item">TEXTTEXTTEXTTEXT</div>
<div class="carousel__item">TEXTTEXTTEXTTEXT</div>
<div class="carousel__item">TEXTTEXTTEXTTEXT</div>
<div class="carousel__item">TEXTTEXTTEXTTEXT</div>
<div class="carousel__item">TEXTTEXTTEXTTEXT</div>
<div class="carousel__item">TEXTTEXTTEXTTEXT</div>
<div class="carousel__item">TEXTTEXTTEXTTEXT</div>
</div>