S
S
strify_252016-06-27 13:47:49
JavaScript
strify_25, 2016-06-27 13:47:49

Replacing search with a basket when scrolling?

There is a menu fixed when scrolling the page. The block also has a search. When scrolling down, the search is replaced with a basket. If you scroll back to the top, the search appears again, but it no longer works! How can this be fixed? Here is a script with fixing and replacing elements

$(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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2016-06-27
@SPAHI4

The problem is probably with replaceWith. Try to just hide what you want with hide()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question