Use a DOM ready function, what you have is just a IIFE, then attach an actual event handler on resize, and trigger the event to fire it on pageload :
jQuery(function($) {
$(window).on('resize', function() {
if ($('#wpadminbar').length) {
$('#menu, .pure-menu-link').css('top', $('#wpadminbar').height());
}
}).trigger('resize');
});