0
I want to make a simple effect, which would be to apply an effect of animate
in a div
, increasing her height after scrolling the page and, when the page scrolled to the top again, that div
back to the initial style.
CSS
<style>
.geral-boxes{
width: 100%;
float: left;
}
.box1,.box2,.box3{
width: 100%;
float: left;
height: 500px;
}
.box1{
background-color: #fff;
}
.box2{
background-color: #fff;
}.box3{
background-color: #fff;
}
.geral-boxes{
width: 100%;
float: left;
}
.laranja{
width: 100%;
float: left;
}
.scroll-aparecer{
width: 50px;
float: left;
height: 0px;
background-color: #000;
}
SCRIPT
$(document).ready(function(){
$(window).on('scroll', function() {
if($(window).scrollTop() > 200) {
$('.scroll-aparecer').animate({
height:"100px"
}, 1000); /*Defina aqui o tempo em milisegundos */
}else{
$('.scroll-aparecer').animate({
height:"0"
}, 1000); /*Defina aqui o tempo em milisegundos */
}
});
});
HTML
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="scroll-aparecer"></div>
What’s the best way to do that?
Thanks for the answer. There is a way to make this scroll not take the distance from the top of the page but refer to some element?
– maiquel
@maiquel yes, just take the distance of the element you want to refer to the top + the height of it. See if this is it: https://jsfiddle.net/pzeemo0f/
– Sam
@maiquel If you found the answer helpful, make sure to dial ✔
– Sam