Trying to synchronize two divs while scrolling. Essentially, I have a page scroll and want to fix the second div when it reaches the top.
Please refer to the gif icon attached for clarification.
You can view my progress so far here.
The current issue in my code is that both divs reach the top simultaneously as I scroll.
This is the jQuery code being used:
jQuery(document).on('ready', function() {
"use strict";
/* -------------------------------------
Set Page Height
-------------------------------------- */
function headerFullScreen() {
var _vph = jQuery(window).height();
jQuery('#header').css({'height': _vph + 'px'});
}
function imgBoxFullscreen() {
var _vph = jQuery(window).height();
jQuery('#imgbox').css({'height': _vph + 'px'});
jQuery(window).scroll(function(){
if(jQuery(window).scrollTop() >= _vph - 68){
jQuery('.navigationarea').addClass('ontop');
}
})
}
window.onresize = function() {
headerFullScreen();
imgBoxFullscreen();
}
var refreshId = setInterval(refresh, 500);
function refresh() {
headerFullScreen();
imgBoxFullscreen();
}
/* -------------------------------------
FIXED LOGO AND NAV
-------------------------------------- */
jQuery(window).scroll(function(){
var scrollTop = 1;
if(jQuery(window).scrollTop() >= scrollTop){
jQuery('.logoholder, .navigationarea').css({
position : 'fixed',
top : '0',
margin : '0'
});
jQuery('.navigationarea').addClass('ontop-mobile');
jQuery('.navigationarea').addClass('ontop');
jQuery('.menu_lis').addClass('top_menu');
jQuery('.straight-menu').addClass('hide_bottom_menu');
}else{
jQuery('.navigationarea').removeClass('ontop-mobile');
jQuery('.navigationarea').removeClass('ontop');
jQuery('.menu_lis').removeClass('top_menu');
jQuery('.straight-menu').removeClass('hide_bottom_menu');
}
if(jQuery(window).scrollTop() < scrollTop){
jQuery('.logoholder').removeAttr('style');
jQuery('.navigationarea').removeClass('ontop-mobile');
jQuery('.navigationarea').removeClass('ontop');
jQuery('.navigationarea').removeAttr('style');
}
})
});
I have also included a gif demonstrating how it is supposed to function.https://i.sstatic.net/i9zbT.gif