Not great but put this in the scroll event as the calculation can be made before the heading is added to the page
Better check on media dialog
Control the visibility of the meta button