JSFiddle - React, Tailwind, and code Playground

HTML

<div id="enano">algo aquí</div>

<div id="elemento">¿Hola?</div>

<div id="grande"></div>

CSS

.fixed {
    position: fixed;
    top: 0;
}

/* Todo lo demás es a efectos de muestra */

#elemento {
    padding: 10px;
    background-color: firebrick;
    color: #fff;
    width: 100%;
}

#enano {
    padding: 20px 0;
}

#grande {
    height: 9999px;
}

JavaScript

$(function () {
  
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6) {
    var top = $('#elemento').offset().top - parseFloat($('#elemento').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#elemento').addClass('fixed');
      } else {
        // otherwise remove it
        $('#elemento').removeClass('fixed');
      }
    });
  }  
});