I have a white menu icon in PNG format that I want to change to green menu icon in PNG format and I tried to use the fading effect. It works at first and changes on scroll but when I keep scrolling it keeps flickering the green icon, however it stops when I stop scrolling as well. I'm not sure why this is happening or how can I fix it, couldn't really find the related questions. I'd appreciate your help. Thanks in advance here is my code:
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 50) {
$(".show_nav img").fadeOut(function() {
$(this).attr("src","../img/icons/menu-green.png").fadeIn();
});
} else {
$(".show_nav img").fadeOut(function() {
$(this).attr("src","../img/icons/menu-white.png").fadeIn();
});
}
});