In this blog! I am going to tell you how to create Dynamic Content Load using jQuery. Generally, we see the content loader on many websites and on some registration form when we click on the next step button after completed the current step, before it takes us on next page it takes sometime to load the next page and in that time period, it shows the circle rotating.
So if you want to add loader in your site the code below will help you
$('.button').prop('disabled', 'true'); /* after clicked, button will be disabled */
$('#loader').hide(); /*hide loader image */
$('.content').show(); /*show content */
}, 1000); /* taking time to loading the the content */
In the above code, when we click the button, loader will start rotating till the content is not loaded and then after loading the content the clickable button and loader image will get disabled.
In above code, I have hidden loader image and content using block level property “display:none”. The essential property used here is position: absolute and the parent element button is first positioned relative.
Output: Below is the output of loader image rotating on the button.
first image shows simple button, second with loader and third after loading content
<button class="button" >loader
<img id="loader" src="http://besseges2016.squaresystem.co.uk/images/slider/loading.gif">
Prime Minister Narendra Modi met senior officials on Monday to review the pros and
cons of the India-Pakistan Indus Waters Treaty amid growing pressure on New Delhi to
scrap the agreement.