Can sombody help me
I'm trying to change the color of the text active slide.
So if Slide 1 is active then the text "Slide 1" at the bottom of the screen should turn yellow the other 2 stay white.
and if slide 2 is active "Slide 2" should turn yellow enz.
the code that i am using is: "https://codepen.io/omairatiq/pen/wvBoGaE
"
$(document).ready(function(){
$(".slider").slick({
infinite: true,
arrows: false,
dots: false,
autoplay: false,
speed: 800,
slidesToShow: 1,
slidesToScroll: 1,
});
var percentTime;
var tick;
var time = 1;
var progressBarIndex = 0;
$('.progressBarContainer .progressBar').each(function(index) {
var progress = "<div class='inProgress inProgress" index "'></div>";
$(this).html(progress);
});
function startProgressbar() {
resetProgressbar();
percentTime = 0;
tick = setInterval(interval, 10);
}
function interval() {
if (($('.slider .slick-track div[data-slick-index="' progressBarIndex '"]').attr("aria-hidden")) === "true") {
progressBarIndex = $('.slider .slick-track div[aria-hidden="false"]').data("slickIndex");
startProgressbar();
} else {
percentTime = 1 / (time 5);
$('.inProgress' progressBarIndex).css({
width: percentTime "%"
});
if (percentTime >= 100) {
$('.single-item').slick('slickNext');
progressBarIndex ;
if (progressBarIndex > 2) {
progressBarIndex = 0;
}
startProgressbar();
}
}
}
function resetProgressbar() {
$('.inProgress').css({
width: 0 '%'
});
clearInterval(tick);
}
startProgressbar();
$('.progressBarContainer div').click(function () {
clearInterval(tick);
var goToThisIndex = $(this).find("span").data("slickIndex");
$('.single-item').slick('slickGoTo', goToThisIndex, false);
startProgressbar();
});
});
h3 {
margin:5px 0;
color: black;
}
.sliderContainer {
position: relative;
}
.slider {
width: 500px;
margin: 30px 50px 50px;
}
.slick-slide {
background: #3a8999;
color: white;
padding: 80px 0 120px;
font-size: 30px;
font-family: "Arial", "Helvetica";
text-align: center;
}
.slick-prev:before,
.slick-next:before {
color: black;
}
.slick-dots {
bottom: -30px;
}
.slick-slide:nth-child(odd) {
background: #e84a69;
}
.progressBarContainer {
position: absolute;
bottom: 20px;
width:300px;
left:150px;
}
.progressBarContainer div {
display: block;
width: 30%;
padding: 0;
cursor: pointer;
margin-right: 5%;
float: left;
color: white;
}
.progressBarContainer div:last-child {
margin-right: 0;
}
.progressBarContainer div span.progressBar {
width: 100%;
height: 4px;
background-color: rgba(255, 255, 255, 0.4);
display: block;
}
.progressBarContainer div span.progressBar .inProgress {
background-color: rgba(255, 255, 255, 1);
width: 0%;
height: 4px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css" rel="stylesheet"/>
<body>
<div class="sliderContainer">
<div class="slider single-item">
<div>Slide1</div>
<div>Slide2</div>
<div>Slide3</div>
</div>
<div class="progressBarContainer">
<div>
<h3>Slide 1</h3>
<span data-slick-index="0" class="progressBar"></span>
</div>
<div>
<h3>Slide 2</h3>
<span data-slick-index="1" class="progressBar"></span>
</div>
<div>
<h3>Slide 3</h3>
<span data-slick-index="2" class="progressBar"></span>
</div>
</div>
</div>
</body>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
Sorry for my bad englis.
CodePudding user response:
You can customize this script in this way.
In function Interval() in js file, above the this line
$('.inProgress' progressBarIndex).css({
width: percentTime "%"
});
Add this part
$('.inProgress').parent().parent().removeClass("yellow-text");
$('.inProgress' progressBarIndex).parent().parent().addClass("yellow-text");
And add this line in css file
.yellow-text h3{
color :yellow;
}
Finally , Full Interval function is
function interval() {
if (($('.slider .slick-track div[data-slick-index="' progressBarIndex '"]').attr("aria-hidden")) === "true") {
progressBarIndex = $('.slider .slick-track div[aria-hidden="false"]').data("slickIndex");
startProgressbar();
} else {
percentTime = 1 / (time 5);
$('.inProgress').parent().parent().removeClass("yellow-text");
$('.inProgress' progressBarIndex).parent().parent().addClass("yellow-text");
$('.inProgress' progressBarIndex).css({
width: percentTime "%"
});
if (percentTime >= 100) {
$('.single-item').slick('slickNext');
progressBarIndex ;
if (progressBarIndex > 2) {
progressBarIndex = 0;
}
startProgressbar();
}
}
}
Check here in detail
https://codepen.io/jamesjo29155352/pen/NWjOrrx