I have a website where I am using two different logos on scroll, but I use only one if the screen is less than 1024px.
Everything works as expected, except on screen resize that this breaks. It doesn't show any of the logos on the header, but if I refresh the page, it works...
This is my code:
HTML
<div class="container clearfix" >
<h2 id="logo"><a rel="home" href="#">LOGO ONE</a></h2>
<h2 id="logo2"><a rel="home" href="#"><span>LOGO</span> <br/>TWO</a></h2>
</div>
JS
$(document).ready(function() {
//Main menu animation
$(function () {
if($(window).width() >= 1023){
var targetOffset = $("#section--4").offset().top;
var $w = $(window).scroll(function() {
if ( $w.scrollTop() + 200 > targetOffset ) {
$("#logo").fadeIn(1000);
$("#logo2").fadeOut('slow');
$("header").css({"overflow": "hidden"});
} else {
$("#logo2").fadeIn(2000)
$("#logo").fadeOut('slow');
$("header").css({"overflow": "visible"});
}
});
}
});