5
I wrote a code in which he creates a slide of images in a div
, I wonder if with Javascript it is possible to know the name of the image you are passing on the slide, because when the image appears, I want a descriptive text about it in a div
next door.
I searched but could not find a way to know the name of the image 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?
In case I have to use another medium or if you know any better, please give me a hand.
Follows 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>
The way you’re doing the only way to get the name is by the same link.
– Lucas Fontes Gaspareto
In your case I would do as follows: load an array with the link plus name and every time you select the index loads the link and the name for an element in HTML, you can understand ?
– Lucas Fontes Gaspareto