Add and Remove Class from a section on Scroll

Add and Remove Class from a section on Scroll
jQuery(document).ready(function () {
    
    $(document).scroll(function() {
      var scrolled    = $(document).scrollTop(); 
      var bannerht    = $('.inner-banner').height();
      var content     = $('.blog-detail-content').height();

      var p = $( '.blog-detail-text' ).first();
      var position = p.position();
     

      var leftcontentwidth  = $('.blog-detail-text').width();
      var stickysidebarwidth = parseInt(leftcontentwidth) + parseInt(position.left) + 50;



      $('.sticky').css('left', stickysidebarwidth);
      $('.sticky').css('right', 0);
      
      if(scrolled > bannerht){
        $('.amaxra-sidebar').addClass('sticky');

      }

      if(scrolled < bannerht || scrolled > content){
        $('.amaxra-sidebar').removeClass('sticky');

      }


    })
});

Leave a Reply

Your email address will not be published. Required fields are marked *