Replacement of the basket in best personal Finance?

There is a menu fixed when scrolling the page. In the block there is also a search. When you scroll down, the search is replaced by a basket. If you scroll back up - appears again search, but it no longer works! How can I fix it? Here is a script with fixing and replacement of components
$(document).ready(function(){ 

var $menu = $(".vnesh-plashka"); 
var $cart = $("#cart"), 
$search = $("#search"); 

$(window).scroll(function(){ 
if ( $(this).scrollTop() > 140 && $menu.hasClass("default") ){ 
$menu.fadeOut('fast',function(){ 
$(this).removeClass("default") 
.addClass("fixed") 
.fadeIn('slow'); 
}); 
$("#search").replaceWith($cart); 
} else if($(this).scrollTop() <= 140 && $menu.hasClass("fixed")) { 
$menu.removeClass("fixed").addClass("default"); 
$(".vnesh-plashka #cart").replaceWith($search); 
$(".cartt").append($cart); 
} 
});//scroll 
});

e7793278994f4fd586c779d00440c9db.JPG
July 8th 19 at 11:44
1 answer
July 8th 19 at 11:46
Probably the problem is in replaceWith. Just try to hide in hide()

Find more questions by tags jQueryOpenCart