XF 2.0 js anchor adjustment

MJ0730

Active member
Trying to adjust the page to offset a fixed header.
JavaScript:
function offsetAnchor() {
  if (location.hash.length !== 0) {
    window.scrollTo(window.scrollX, window.scrollY - 40);
  }
}

$(document).on('click', 'a[href^="#"]', function(event) {
  window.setTimeout(function() {
    offsetAnchor();
  }, 0);
});

window.setTimeout(offsetAnchor, 0);

Works outside of xF. In xF, if I use <script> I get an error ($ undefined), and if I put it in <xf:js> nothing happens. What am I doing wrong?
 
Top Bottom