garand / sticky

jQuery Plugin for Sticky Objects
Other
3.3k stars 1.06k forks source link

How disable stick when it is reaches the bottom of it's parent div? #252

Open dhanilkumart opened 7 years ago

dhanilkumart commented 7 years ago

How to disable the stick event when it is reaches the bottom of it's parent div?? I want that div only stick in it's parent div

jeremyxwing commented 7 years ago

You could do something like this, I use it to disable Sticky when it hits the footer.

https://gist.github.com/remyo/7c8c8117723968c2700f0d9110f3c3a1

ghost commented 7 years ago

Nice trick but makes very bad UX Updated gist for instant action.

$(document).ready(function(){ $window = $(window); $window.scroll(function() { var element_1 = $(".sidebar"); var element_2 = $(".footer"); var element_1_top = element_1.offset().top; var element_2_top = element_2.offset().top; var element_1_bottom = element_1_top + element_1.height(); var element_2_bottom = element_2_top + element_2.height();

if (element_1_bottom >= element_2_top && element_1_top < element_2_bottom) {
    $(".sidebar").unstick();
}

}); });