I apologize in advance if this is a simple question, but I am a novice and am having an extremely difficult time resolving a glitch that occurs when triggering a CSS transition on mouseover.
I am using JS to trigger an inversion of color and background images based on the position of the mouse on the screen. If a user moves their mouse to the bottom 50% of the screen, the JS adds the class 'white' to the tag.
This changes the color of all text on the page and loads a different background image.
I think that I am facing two issues:
After the initial page load, the transition flickers once. I believe this may be because the image isn't pre-loaded. I am not sure how I can easily do this in my current situation.
When mousing between the bottom and top half of the screen quickly I notice the same type of flickering behavior. However, when I allow the transition to complete, I can move between both states smoothly without flickering. I cannot understand what is causing this inconsistent behavior.
<style>
#home {
background-color: #191919;
background: url(../img/Profile1.jpg) no-repeat center center fixed;
background-size: cover;
transition: all 900ms cubic-bezier(0.455, 0.03, 0.515, 0.955);
}
#home.white{
background-color: white;
background: url(../img/Profile2.jpg) no-repeat center center fixed;
background-size: cover;
}
</style>
<div id="split-container">
<div class="split-top">
<div class="container-s">
<div class="row">
<div class="col-12">
<h1 class="center offwhite">A UI/UX designer dedicated to creating thoughtful digital experiences.</h1>
</div>
</div>
</div>
</div>
<div class="split-bottom invert-trigger">
<div class="container-s">
<div class="row">
<div class="col-12">
<h1 class="center offblack">An avid traveller seeking new perspectives and meaningful connections.</h1>
</div>
</div>
</div>
</div>
</div>
<script>
winWidth=$(window).width();
if (winWidth >=752) {
$('.invert-trigger').hover(function(){
$('body').addClass('white');
}, function(){
$('body').removeClass('white');
});
$('.invert-trigger').hover(function(){
$('.invert').addClass('black');
}, function(){
$('.invert').removeClass('black');
});
}
});
</script>
Thank you for any help you can provide to resolve these challenges!