Roll div to a point and stop

Asked

Viewed 21 times

0

I’m trying to do something that should be simple but I’m not getting it. I want to take a div that has a form and make it roll with the page to a certain point on the page, let’s say the middle of it, stop there even if the user goes down the page the form will stand there, and will only move up if it goes up more.

My code instead of stopping the div is making it disappear and back when it comes back to the point that stopped.

$(function () {
$(window).scroll(function () {
    if ($(this).scrollTop() > $('.diferenciais').offset().top) {
        $('.span-form').removeClass('fixed-nav');
        $('.span-form').addClass('static-nav');
    } else {
        $('.span-form').removeClass('static-nav');
        $('.span-form').addClass('fixed-nav');
    }
});

});

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.