Hello Coders, today i will show you how you can Show Preloader Using jQuery. With click on single link you can show a preloader. Follow code below,
Source Code of Show Preloader Using jQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ var myVar; //here is a Div ID of the link</strong></span> $( "#myDiv" ).click(function() { myFunction(this); }); //call loader with loader div ID</strong></span> function myFunction(div) { $("#loader").toggle(); $(div).toggle(); setTimeout(function(){ window.location = "https://codingtasks.net"; }, 3000); } }); </script> </head> <body> <button id="myDiv">Go to Website</button> <div id="loader" style="display:none;padding:150px"> <img src="https://i.pinimg.com/originals/78/e8/26/78e826ca1b9351214dfdd5e47f7e2024.gif" width="250px" height="200px"> </div> </body> </html> |
Copy and paste this code in your code Editor save with .html extension and run on your browser.
Code Explanation:
- Here we first include the jQuery CDN.
- Create a HTML button where we click to shows the loader.
- Set the loader image on HTML div.
- Create a function where toggle the loader div and set the timeout time using setTimeout() function to show preloader and then open website.
Your result look like this, but you can change .gif according to yourself.
Also Check:
- CSS Background Image Text Effect
- Create Date Picker using Materialize Framework
- 3D Loader using CSS
- Infinite Loader Using HTML and CSS
- Glowing animated Preloader Design
Happy Coding..!
Was this article helpful?
YesNo