$(function() {
function makeLoader(cnt, img) {
return $("<div>", {
class: "ui-datepicker-loading"
})
.css({
background: "rgba(0,0,0,0.65)",
width: "272px",
height: "224px",
"border-radius": "3px",
color: "white",
"text-align": "center"
})
.html("<p style='padding-top: 100px'>" + cnt + "</p><img width='20' src='" + img + "'></img>")
.appendTo("body")
.hide();
}
function showLoader(tObj) {
$(".ui-datepicker-loading").show().position({
my: "left top",
at: "left+3 top+3",
of: tObj
}).css("z-index", 1001);
}
function hideLoader() {
$(".ui-datepicker-loading").hide().position({
my: "left top",
at: "left-300 top-300",
of: $("body")
}).css("z-index", 0);
}
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
onChangeMonthYear: function(yy, mm, dp) {
showLoader($(this).datepicker("widget"));
setTimeout(hideLoader, 2000);
}
});
var l = makeLoader("Getting dates...", "https://i.gifer.com/ZKZg.gif");
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p>Date: <input type="text" id="datepicker"></p>