1
Some doubts:
1 ) If we reduce the height
of browser amending the resolution, the div.slider
does not follow the height of div.slide
. That is, it remains at the same height. Therefore, the image becomes small, the div.slider
high and the controls next and previous down there.
2 ) A SPAN that is the descriptions of images this above the NAV that houses the navigation buttons. The problem here is that I can’t navigate because of that. And, if I put the SPAN with a small size and throw it forward then I can navigate, but I can’t centralize the SPAN.
3 ) There is still one last doubt. But this is at the same level of teaching. In the code below is:
.slide {
position: absolute;
display: none;
width: 100%;
height:100%;
}
But if I put div.slide
instead of .slide
, although it is a div, the slide some and page loads blank. What is happening at this event?
Can someone please help me?
Code below:
$(document).ready(function(e) {
function startslider(dir) {
ativa = $("div.slider div.ativa")
ativa.removeClass("ativa");
if(dir == -1)
$('div.slider').prepend($('div.slider div.slide').last());
else
$('div.slider nav').before(ativa);
$('div.slider div.slide').eq(0).addClass('ativa');
timer = setTimeout(startslider, 2000);
}
$('div.slider nav button.proximo').on('click', function() {
clearTimeout(timer);
startslider(1);
});
$('div.slider nav button.anterior').on('click', function() {
clearTimeout(timer);
startslider(-1);
});
var timer = setTimeout(startslider, 2000);
});
* {
margin: 0;
padding: 0;
}
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
@keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
div.slider {
position: relative;
width: 100vw;
height:360px;
overflow: hidden;
}
.slide {
position: absolute;
display: none;
width: 100%;
height:100%;
}
.ativa {
display: block;
}
.ativa img {
width:100%;
height:auto;
animation: slider 1s linear;
animation-fill-mode: forwards;
}
@keyframes slider {
0% {
transform: scale(1);
}
100% {
transform: scale(1.1);
}
}
.ativa img:hover {
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
div.slider div.slide span {
position: absolute;
width: 100%;
bottom: 0;
height: 40px;
line-height: 40px;
text-align: center;
color: rgb(255,255,255);
z-index: 500;
}
div.slider nav {
position: absolute;
width: 100%;
height: 40px;
bottom: 0;
text-align: center;
background-color: rgb(0, 0, 0, .5);
z-index: 400;
}
div.slider nav button.anterior, div.slider nav button.proximo {
position: absolute;
width: 100px;
height: 40px;
text-align: center;
}
div.slider nav button.anterior {
left: 10%;
}
div.slider nav button.proximo {
right: 10%;
}
div.slider nav button.proximo label {
top: calc(50%-20px);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="slider">
<div class="slide ativa">
<img class="fade" src="http://funerariasaopedro.net.br/novo/_img/_banner/_site/bg_1.jpg" />
<span>Este é 1</span>
</div>
<div class="slide">
<img class="fade" src="http://funerariasaopedro.net.br/novo/_img/_banner/_site/bg_2.jpg" />
<span>Este é 2</span>
</div>
<div class="slide">
<img class="fade" src="http://funerariasaopedro.net.br/novo/_img/_banner/_site/bg_3.jpg" />
<span>Este é 3</span>
</div>
<nav>
<button class="anterior">Anterior</button>
<button class="proximo">Próximo</button>
</nav>
</div>
@Valdeir PSR, is there
– Carlos Rocha