Tuesday 30 January 2018

Add class after some scroll and remove class when footer appear on screen window in jQuery

<script>
      jQuery(document).ready(function(e) {

    var screen_height = jQuery(window).height();

    var document_height = jQuery(document).height();

    var footer_height = jQuery(".footer").height();

     var max_scroll_height = document_height - screen_height;

    jQuery(window).on('scroll', function(e) {

        var scroll = jQuery(window).scrollTop();

        var element_in_view = scroll > 300;

        var has_reached_bottom_of_page = max_scroll_height - footer_height;

        if (scroll > 300 && scroll < has_reached_bottom_of_page) {

            jQuery('.btSidebar').addClass("changefixed");

        } else {

            jQuery('.btSidebar').removeClass("changefixed");
        }
    });
});
</script>