The Wayback Machine - https://web.archive.org/web/20250114160518/https://www.geeksforgeeks.org/jquery-image-progressbars-plugin/
Open In App

jQuery Image ProgressBars Plugin

Last Updated : 13 Jul, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will learn how to implement image ProgressBar feature using the jQuery Image ProgressBar plugin.

Note: Please download the jQuery Image ProgressBar plugin in the working folder and include the required files in the head section of your HTML code.

<link href=”progressbar.css” rel=”stylesheet” type=”text/css”/>
<script src=”jquery-3.3.1.min.js”></script> <script src=”jquery.progressbar.js”></script>

Example: The following example demonstrates the basic functionality of Image ProgressBar plugin using jQuery createProgress() and getRandomNumber() functions. These functions make use of the plugin’s SetPercentage() method for setting the percentage complete. For getting random numbers, JavaScript’s Math.ceil() and Math.floor() are used. The background image along with the image selected for the progress bar is set. The plugin’s option backgroundOpacity is also set in the jQuery part of the code.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>jQuery Image Progress bars</title>
    <style>
        html {
            font-family: "Helvetica Neue",
                Arial, sans-serif;
 
            background-color: #e6e6e6;
        }
    </style>
 
    <link rel="stylesheet"
          type="text/css"
          href="progressbar.css">
    <script type="text/javascript"
            src="jquery-3.3.1.min.js">
    </script>
    <script type="text/javascript"
            src="jquery.progressbar.js">
    </script>
</head>
 
<body>
    <h2>jQuery Image Progressbar</h2>
    <div id="imageDivID">
    </div>
 
    <script type="text/javascript">
        $(document).ready(function () {
            let myimage = $("#imageDivID").progressBar({
                imageUrl: 'images/gfg2.jpg',
                backgroundImageUrl: 'images/geeksimage.png',
                imageHeight: 280,
                imageWidth: 300,
                backgroundOpacity: 0.5
            });
 
            createProgress(myimage, 0);
 
        });
 
        function createProgress(
            imageProgressBar, currentVal) {
            let increment = getRandomNumber(0, 3);
            let newVal = currentVal + increment;
            if (newVal > 100) newVal = 100;
            if (currentVal == 100) newVal = 0;
            imageProgressBar.SetPercentage(newVal);
            setTimeout(function () {
                createProgress(imageProgressBar, newVal);
            }, 100);
        }
 
        function getRandomNumber(minVal, maxVal) {
            min = Math.ceil(minVal);
            max = Math.floor(maxVal);
            return Math.floor(Math.random()
                * (max - min + 1)) + min;
        }
    </script>
</body>
 
</html>


Output:


Become a Full-Stack Developer and also get 90% fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.

After successfully processing refunds worth over INR 5 Cr, GeeksforGeeks is back with the Three 90 challenge and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!


Next Article

Similar Reads

three90RightbarBannerImg