I'm just using a setInterval to animate my elements, and I aim to do something when index === 5
, which is incrementing inside the setInterval's function,
but I can't refer to that index to console.log()
something or do whatever, how should I do that?
let index = 0;
function slideAction(nth) {
console.log(index)
index++;
}
let IntervalID = null;
function slideActionIntervalManager(flag, slideAction, nth) {
if (flag){
intervalID = setInterval(function () { slideAction(nth); }, 1000);
}
else
clearInterval(intervalID);
}
function firstStartSlide (){
slideActionIntervalManager(true,slideAction, 1)
if (index === 5){
console.log('if true')
}
else if (index === 9){
alert()
}
}
firstStartSlide();
*{
padding: 0;
margin: 0;
}
/*--- slideWrapperContainer ---*/
.main{
margin: 100px auto;
border: 5px solid #000;
position: relative;
width: 700px;
height: 360px;
/*overflow: hidden;*/
}
/*------- slideWrapper ------*/
.outer-img-wrapper{
width: 100%;
height: 100%;
}
/*---------- slide ----------*/
.img-wrapper{
border: 2px solid red;
position: absolute;
top: 0;
left: 100%;
height: 360px;
width: 3500px;
}
img{
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Aucun commentaire:
Enregistrer un commentaire