jerneva jerneva - 7 months ago 27
HTML Question

Returns fixed cart to original position after scroll down

I have a fixed shopping cart that works perfectly. On page load the cart is positioned 350px from the top of the page, after scrolling 350px down the page the shopping cart becomes fixed to the page, my problem is the shopping cart on scroll up the shopping cart goes all the way back to the top of the page, instead of going back to its original position.

How do i do that?



$(window).on("scroll", function() {
if($(window).scrollTop() > 350) {
$("#stickycart").css("margin-top", "0","right",$(window).scrollTop());

}
});

#stickycart{
width: 25%;
float:right;
margin: 20px;
margin-top:450px;
float:right;
right:0;
top:0;
margin-right: 4%;

position: fixed;
}

<div id="stickycart">
<p id='order'>My Order</p>
<p id='estimated'>Average Delivery <br>
<b id='avg'><?php echo $avg_del ?></b><br> minutes</p>
<div id="prods_here">
<!-- PLACE PRODUCTS HERE-->
<?php cart(); ?>
</div>
</div>




Answer

I cannot find consistency in your code because #stickycart is not present in your HTML. However, this is probably what you want: http://codepen.io/anon/pen/jqdYVd