I am using google fonts api. In document.ready i requested the google fonts collection and populate the select list with all available font-families. Now when user select any font from selectlist i just append the link in the document which request the selected font and show the font-preview. But i am trying to show the loading image while the font is loading for preview. My code :
$("#ff").selectmenu({ select: function () {
var img = $("<img />").attr("src", "/images/load.gif");
$(".preview").append(img);
$('body').append("<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=" + escape($(this).val()) + "' type='text/css' media='all' />");
$(".preview").css({ fontFamily: $(this).val() });
$(img).remove();
}
});
But the loading image is not showing because may be the link tag is requesting the font asynchronously. How can i show the loading image until the font is fully loaded ?