JSFiddle - React, Tailwind, and code Playground

by luka kupunia

HTML

<div class="item">
    <img src="http://picsum.photos/400/400" alt="">
    <p>1</p>
</div>
<div class="item">
    <img src="http://picsum.photos/400/400" alt="">
    <p>2</p>
</div>

<div class="dots">
    <button class="dot">1</button>
    <button class="dot">2</button>
    <button class="dot">3</button>
    <button class="dot">4</button>
</div>

CSS

body {
    overflow: hidden;
    padding-top: 300px;
}
.item {
    height: 300px;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    width: 100%;
}
.item img {
    width: 100%;
    height: 100%;
}
.item p {
    font-size: 150px;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin: 0;
    background: black;
    padding: 50px;
}

JavaScript

function mainSlider(){
	var imageSrc = [
    	'http://picsum.photos/400/400',
        'http://picsum.photos/300/300',
        'http://picsum.photos/500/500',
        'http://picsum.photos/600/600'
    ],
    texts = [ '1' , '2' , '3' , '4' ],
    current = 0,
    time = 0;
    
    function changeSlide(){
    	console.log(time)
    }
    
    function sliderTime(){
    	time++;
    	if(time > 240){
        	changeSlide();
            time = 0;
        }
    	requestAnimationFrame(sliderTime);
    }
    sliderTime();
}
mainSlider();