I wrote a code in which it creates a slide of images in a div
, I would like to know if with Javascript it is possible to know the name of the image that is passing on the slide, because when the image appears, I want a text to appear descriptive on it in a div
on the side.
I searched but could not find a way to know the image name through Javascript.
Is there any way to do this with Javascript, or will I have to use another way to make the text appear according to the image? If you have to use another medium or if you know some better, please give me some help.
Follow the code:
#slideShow {
background-color:#eeeeee;
width:400px;
height:150px;
border:2px solid darkgray;
-webkit-transition: background-image 2s;
}
div#anterior {
width:100px;
height:300px;
transition: 2s;
text-align:center;
font-size:0px;
}
div#anterior:hover {
background-color:white;
opacity:0.4;
font-size:150px;
}
div#proximo {
width:100px;
height:300px;
transition: 2s;
margin-left:300px;
margin-top:-300px;
text-align:center;
font-size:0px;
}
div#proximo:hover {
background-color:white;
opacity:0.4;
font-size:150px;
}
function iniciarSlide() {
max = 6;
min = 1;
fi = min;
carregarFoto("f1.jpg");
tr = true;
document.getElementById("slideShow").addEventListener("transitionend", fimTr)
}
function fimTr() {
tr = true;
}
function carregarFoto(foto) {
document.getElementById("slideShow").style.backgroundImage="URL("+foto+")";
}
function prox() {
if(tr == true) {
tr = false;
fi++;
if (fi > max) {
fi = min;
}
carregarFoto("f"+fi+".jpg");
}
}
function ant() {
if (tr = true) {
tr = false;
fi--;
if (fi < min) {
fi = max;
}
carregarFoto("f"+fi+".jpg");
}
}
<body onload="iniciarSlide()">
<div id="slideShow">
<div id="anterior" onclick="ant()"></div>
<div id="proximo" onclick="prox()"></div>
</div>
</body>