set new offset_top for stick_in_parent

Viewed 275

I used the sticky-kit framework for the Jquery to fix the sidebar. And I did it successfully, and it's like that

And this site has put this code in its js section . offset_top: 10

This height is maintained from both the scroll down and the scroll up mode. And it works right

I want to change this to 10 pixels if you scroll up. And if you scroll down, have a distance of 0 pixels

And so I wrote the code below, but it doesn't work:

            if (scroll_to_top) {
                    $("#aside").stick_in_parent({
                        offset_top: 10
                    });
            }
            if (scroll_to_down) {
                    $("#aside").stick_in_parent({
                        offset_top: 0
                    });
            }

What should I do?

2 Answers

Try this:

        if (scroll_to_top) {
                $("#aside").css({
                    "top": "10px"
                });

        }
        if (scroll_to_down) {
                $("#aside").css({
                    "top": "0px"
                });
        }

In order to set new offset_top you should remove sticky kit and restore element by triggering 'sticky_kit:detach' event:

if (scroll_to_top) {
  $("#aside").trigger('sticky_kit:detach');
  $("#aside").stick_in_parent({
    offset_top: 10
  });
}
if (scroll_to_down) {
  $("#aside").trigger('sticky_kit:detach');
  $("#aside").stick_in_parent({
    offset_top: 0
  });
}
Related