Stick a Div

jQuery

var stickyElement = $( "#list-faq-wrap" );
var stickyElementPos = stickyElement.offset();
$( window ).scroll( function () {
	var windowpos = $( window ).scrollTop();
	if ( windowpos >= stickyElementPos.top - 20 ) {
		stickyElement.addClass( "stick" );
	} else {
		stickyElement.removeClass( "stick" );
	}
} );

CSS

.stick {
  position: fixed;
  top: 0;
  z-index: 999;
}

Leave a Reply