I have a div called cop which has a fixed position.
That div should behave same as the questions tab (which is similar) but it is changing its position when page is scrolled .
My Script
$(window).scroll(function()
{
var top = 100 * $(window).scrollTop() / ($(document).height() - $(window).height());
if (top > 40)
{
$(".cart, .top").fadeOut();
}
else
{
$(".cart, .top").fadeIn();
}
});
I have created a working example on CODEPEN. It is easier to understand it in action. First you need to read the scroll event where you can take action on your desired element:
When you scroll more than 300px in this example, your
.copdiv will acquirerelativeposition instead offixed. It will return to original setting when you scroll up. I attempted by different CSS class since it will be easy for you to change styling in any way you want.