I am building my portfolio website and I thought of using the hero section image into the next section of about us by moving and resizing the image, as a guess I have fixed about the height of 700px up to which image has to scroll. But the problem is that it is not working on resizing screen size. Is there a way to move it such that it always fits in about section on scrolling? Below is code snippets and gif showing the problem.
<!--HTMl-->
<section class="hero" id="hero">
<div id="hero-img" class="hero-img" ><img src="main.png"></div>
</section>
/*CSS*/
.hero .hero-img{
margin-left: auto;
position: absolute;
right: 0;
opacity: 1;
bottom: 0;
max-height: auto;
max-width: 100%;
}
.hero .hero-img img{
max-height: 100%;
max-width: 100%;
min-width: 160px;
min-height: 320px;
}
//JavaScript//
$(window).bind('scroll',function(e){
parallaxScroll();
});
function parallaxScroll(){
var scr = $(window).scrollTop();
var scrolled =document.getElementsByName('hero-img').length - $(window).scrollTop();
if(scr<690){
$('.hero-img').css('top',(0-(scrolled*1.1))+'px');
$('.hero-img').css('right',(0-(scrolled*.3))+'px');
}
else
{
$('.hero-img').css('top',('top'-(scrolled*1.1))+'px');
$('.hero-img').css('right',('right'-(scrolled*.3))+'px');
}
}