JSFiddle - React, Tailwind, and code Playground
by satantx
HTML
<div class="list">
<ul>
<li>Первый пункт</li>
<li>Второй</li>
<li>Третий длнный пункт</li>
<li>Четвертый</li>
<li>Ну и последний</li>
</ul>
<div class="marker"></div>
</div>
CSS
body {
background: #2D2C30;
}
.list {
height:40px;
line-height: 40px;
position: relative;
}
.list li {
float: left;
padding: 0 15px;
cursor: pointer;
color: #fff;
}
.marker {
position: absolute;
width: 120px;
height: 40px;
top: 0; left: 0;
border: 3px solid #ff0000;
transition: all 0.5s ease;
background-image: linear-gradient(to right, rgba(39,207,207,.1), rgba(222,0,255,.1));
}
JavaScript
$('li').click(function(){
$('li').removeClass('active');
$(this).addClass('active');
var $activeItem = $(this);
var markerLeft = $activeItem.position().left;
var markerWidth = $activeItem.outerWidth();
var $marker = $('.marker');
$marker.css({
'left': markerLeft + 'px',
'width': markerWidth + 'px'
});
});