1
I have the following structure:
<div class="slideShow">
<div class="boxSlide">
<div class="imagens">
<img src="_imgs/_slideShow/1.png" />
<img src="_imgs/_slideShow/2.png" />
<img src="_imgs/_slideShow/3.png" />
</div>
<div class="anterior">
<span class="setaSpan"><</span>
<span class="boxSpan"></span>
</div>
<div class="proximo">
<span class="setaSpan">></span>
<span class="boxSpan"></span>
</div>
</div>
<div class="contador">
<span class="contaSlide">1</span>
<span class="contaSlide">2</span>
<span class="contaSlide">3</span>
</div>
</div>
TESTE
I wonder if there is a way to make the height of the div.slideShow
, is automatically adjusted to the height of div’s from within.
The idea here is that the browser be adjusted (screen sizes) and the ratio remain.
Before the div.slideShow
, there is only the body
.
What I want to do is that as the screen is being resized, or pulling the brodas of the browser or even through predisposed screens (Nb’s, tablet’s, cell phones, etc...), the height of the div.slideShow
, fits the height of your internal content that is already being resized correctly.
However, if I give fixed height to div.slideShow
, when the images decrease in size, I will have problems.
Imagine the following situation: imagine div.img
I have a imagem
with 300px
of height and decide to trade for another 400px
of height or 200px
. Keeping fixed height in div.slideShow
, I will have problems. Hence the need for automatic adjustment.
How to solve this problem?
Below the running code:
$(document).ready(function(e) {
quantasImagens = $("div.slideShow div.boxSlide div.imagens img").length-1;
contador = 0;
$("div.slideShow div.boxSlide div.anterior").click(function() {
contador = contador==quantasImagens ? -1 : contador;
contador++;
$("div.slideShow div.boxSlide div.imagens img").css("opacity",0);
$("div.slideShow div.boxSlide div.imagens img").eq(contador).css("opacity",1);
});
$("div.slideShow div.boxSlide div.proximo").click(function() {
contador = contador==0 ? quantasImagens+1 : contador;
contador--;
$("div.slideShow div.boxSlide div.imagens img").css("opacity",0);
$("div.slideShow div.boxSlide div.imagens img").eq(contador).css("opacity",1);
});
$("div.slideShow div.contador span.contaSlide").click(function() {
index = $(this).index();
$("div.slideShow div.boxSlide div.imagens img").css("opacity",0);
$("div.slideShow div.boxSlide div.imagens img").eq(index).css("opacity",1);
});
});
* {
margin:0;
padding:0;
}
div.slideShow {
position: relative;
width: 100%;
height:300px;
}
div.slideShow div.boxSlide,
div.slideShow div.contador {
position: relative;
display: block;
width: 100%;
}
div.slideShow div.boxSlide{
height:277px;
}
div.slideShow div.boxSlide div.imagens img {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
}
div.slideShow div.boxSlide div.imagens img:first-child {
opacity: 1;
}
div.slideShow div.boxSlide div.anterior,
div.slideShow div.boxSlide div.proximo {
position: absolute;
display: block;
top: 100px;
}
div.slideShow div.boxSlide div.anterior {
left: 100px;
}
div.slideShow div.boxSlide div.proximo {
right: 100px;
}
div.slideShow div.boxSlide div.anterior span,
div.slideShow div.boxSlide div.proximo span {
position: absolute;
display: block;
width: 30px;
height: 30px;
}
div.slideShow div.boxSlide div.anterior span.boxSpan,
div.slideShow div.boxSlide div.proximo span.boxSpan {
background-color: rgb(200,200,200);
opacity: .5;
z-index: 1;
}
div.slideShow div.boxSlide div.anterior span.setaSpan,
div.slideShow div.boxSlide div.proximo span.setaSpan {
line-height: 30px;
text-align: center;
font-weight: bolder;
cursor: pointer;
z-index: 2;
}
div.slideShow div.boxSlide div span.setaSpan:hover + span.boxSpan {
opacity: 1;
}
div.slideShow div.contador {
/*top:240px;*/
background-color:rgba(240,240,240,.5);
}
div.slideShow div.contador span.contaSlide {
display: inline-block;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
background-color: rgb(200,200,200);
cursor: pointer;
opacity: .5;
}
div.slideShow div.contador span.contaSlide:hover {
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="slideShow">
<div class="boxSlide">
<div class="imagens">
<img src="http://hotplateprensas.com.br/estilos/_imgs/_slideShow/1.png" />
<img src="http://hotplateprensas.com.br/estilos/_imgs/_slideShow/2.png" />
<img src="http://hotplateprensas.com.br/estilos/_imgs/_slideShow/3.png" />
</div>
<div class="anterior">
<span class="setaSpan"><</span>
<span class="boxSpan"></span>
</div>
<div class="proximo">
<span class="setaSpan">></span>
<span class="boxSpan"></span>
</div>
</div>
<div class="contador">
<span class="contaSlide">1</span>
<span class="contaSlide">2</span>
<span class="contaSlide">3</span>
</div>
</div>
oi
then, but this is not solving. For if I put something below the div.total, this content on pro incio da div.total. Well, the images of div.img are with position Absolute and need to be so. That’s it?
– Carlos Rocha
Yes that’s exactly it, postion: Absolute causes the 'exit' element of the normal flow, so it does not fill the parent element
– Bruno Romualdo
Is there any resource? I came up to put a div with clear:Both below but did not resolve
– Carlos Rocha
Do the following, edit your answer and in the menu that appears where you edit the text of the question click on
Trecho Javascript/HTML/Css
and add html/css code to the frames that appear, so we can 'see' your code running and it’s easier to help.– Bruno Romualdo
But as for position: Absolute does not help clear: Both, this works more for floats, probably will have to change this position: Absolute.
– Bruno Romualdo
doubt completely here: https://answall.com/questions/247185/slideshow-n%C3%A3o-works-right-ap%C3%B3s-migrates%C3%A7%C3%A3o, I tried to minimize the problem in our topic. Code running here: http://hotplateprensas.com.br/stilos/slide.php
– Carlos Rocha
Let’s go continue this discussion in chat.
– Bruno Romualdo
done according to your guidance. Note that, as the images have reduced in size accompanying the browser, the menu div has dropped a lot because of the fix height of the main div
– Carlos Rocha
OK join the chat, so it doesn’t get too long here.
– Bruno Romualdo
One more little problem: this time with the arrows. Note that although both are positioned at 100px of the margins, although I switched here to 10%, the right margin kind of is not respecting this when we greatly decrease the browser
– Carlos Rocha
This escapes the main question but I will answer you in chat.
– Bruno Romualdo
If you can give the question as answered thank you :)
– Bruno Romualdo
certainty. By your solution, my mistake was in not turning display:One on the other div’s that were not being shown. So they were all display:block, pushing the others down. That was my mistake. Thank you very much!
– Carlos Rocha
On the div’s of arrows, the idea here was to create a square with background and opacity:0 and when passing the mouse over it, it appears with oacity:1
– Carlos Rocha