search
HomeWeb Front-endJS TutorialA progressbar widget_jquery based on jquery

Demo website for this project http://wijmo.com/Wijmo-Open/samples/

Copy codeThe code is as follows:

/*
* wijprogressbar Widget. V1.0
*
* Copyright (c) Componentone Inc.
*
* Depends:
* Jquery-1.4.2.js
* jquery.ui.core.js
* jquery.ui.widget.js
*
*Optional dependence for effect settings:
* jquery.effects.core.js
* jquery.effects.blind.js
* jquery.effects.bounce.js
* jquery.effects.clip.js
* jquery.effects.drop.js
* jquery.effects.explode.js
* jquery.effects.fold.js
* jquery.effects.hightlight.js
* jquery.effects.pulsate.js
* jquery.effects.scale.js
* jquery.effects.shake.js
* jquery.effects.slide.js
* jquery.effects.transfer.js
* HTML:
*

*/
(function ($) {
$.widget("ui.wijprogressbar", $.ui.progressbar, {
options: {
///
///The label's alignment on the progress bar. The value should be "east", "west", "center", "north", "south" or "running".
///Default:"center".
///Type:String.
///Code sample:$('.selector').wijprogressbar('option','labelAlign','center').
///

labelAlign: "center",
///
///The value of the progress bar,the type should be numeric.
///Default:0.
///Type:Number.
///Code sample:$('.selector').wijprogressbar('option','value',60).
///

maxValue: 100,
///
///The minimum value of the progress bar,the type should be numeric.
///Default:0.
///Type:Number.
///Code sample:$('.selector').wijprogressbar('option','minValue',0).
///

minValue: 0,
///
///The fill direction of the progress bar.the value should be "east", "west", "north" or "south".
///Default:"east".
///Type:String.
///Code sample:$('.selector').wijprogressbar('option','fillDirection','east').
///

fillDirection: "east",
///
///The progressbar's orientation.the value should be 'horizontal' or 'vertical'.
///Default:"horizontal".
///Type:String.
///Code sample:$('selector').wijprogressbar('option','orientation','horizontal').
///

///orientation: "horizontal",
///
///Sets the format of the label text.The available formats are as follows:
///{0} or {ProgressValue} express the current progress Value.
///{1} or {PercentProgress} express the current percent of the progress bar.
///{2} or {RemainingProgress} express the remaining progress of the progress bar.
///{3} or {PercentageRemaining} express the remaining percent of the progress bar.
///{4} or {Min} express the min Vlaue of the progress bar.
///{5} or {Max} express the max Value of the progress bar.
///Default:"{1}%".
///Type:String.
///Code sample:$('.selector').wijprogressbar('option','labelFormatString','{0}%').
///

labelFormatString: "{1}%",
///
///Set the format of the ToolTip of the progress bar,the expression of the format like the labelFormatString.
///Default:"{1}%".
///Type:String.
///Code sample:$('.selector').wijprogressbar('option','toolTipFormatString','{1}%').
///

toolTipFormatString: "{1}%",
///
///The increment of the progress bar's indicator.
///Default:1.
///Type:Number.
///

///Code sample:$('.selector').wijprogressbar('option','indicatorIncrement',10).
indicatorIncrement: 1,
///
///The Image's url of the indicator.
///Default:"".
///Type:String.
///Code sample:$('.selector').wijprogressbar('option','indicatorImage','images/abc.png').
///

indicatorImage: "",
///
///The delay of the progressbar's animation.
///Default:0.
///Type:Number.
///Code sample:$('.selector').wijprogressbar('option',
///

animationDelay: 0,
///
///The options parameter of the jQuery's animation.
///Default:"{animated:'progress',duration:500}".
///Type:Options.
///Code sample:$('.selector').wijprogressbar('option','animationOptions',{animated:'progress',duration:600}).
///

animationOptions: {
animated: 'progress',
duration: 500
}
},
     //when set the options, trigger this method.
_setOption: function (key, value) {
var val, self = this;
switch (key) {
case "value":
val = parseInt(value);
self.options[key] = val;
self._refreshValue(val);
break;
case "maxValue":
case "minValue":
val = parseInt(value);
self.options[key] = val;
self[key === "maxValue" ? "max" : "min"] = val;
self._refreshValue();
break;
case "labelFormatString":
case "toolTipFormatString":
self.options[key] = value;
self._refreshValue();
//$.Widget.prototype._setOption.apply(this, arguments);
break;
case "orientation":
case "fillDirection":
case "labelAlign":
case "indicatorImage":
self.options[key] = value;
self._initElements();
self._refreshValue();
//$.Widget.prototype._setOption.apply(this, arguments);
break;
case "indicatorIncrement":
value = (value == 0 ? 1 : value);
self.options[key] = value;
self._initElements();
self._refreshValue();
break;
default: break;
}
$.Widget.prototype._setOption.apply(self, arguments);
},
     ///create the widget
_create: function () {
var self = this;
self.min = self.options.minValue;
self.max = self.options.maxValue;
self.element.addClass("ui-wijprogressbar");
$.ui.progressbar.prototype._create.apply(self, arguments);
self.label = $("").addClass("ui-progressbar-label ui-corner-left").appendTo(self.valueDiv);
self._initElements();
self._isInit = true;
self._refreshValue();
},
     ///Trigger the pressbar event.
_triggerEvent: function (eventName, oldValue, newValue, cancel) {
var ea = $.Event(eventName);
ea.data = {
oldValue: oldValue,
newValue: newValue,
cancel: cancel
};
this._trigger(eventName, ea);
return ea.data.cancel;
},
    //refresh the progress value.
_refreshValue: function () {
var self = this;
if (!self._isInit) {
return;
}
var value = self.value();
var percent = (value - self.min) / (self.max - self.min) * 100;
var o = self.options;

var cancel = self._triggerEvent("beforeProgressChanging", self.element.attr("aria-valuenow"), value, false);
if (cancel) {
return;
}
self.valueDiv.css({
width: "",
height: ""
});
          // If have animation.
if (o.animationOptions.animated && o.animationOptions.duration > 0) {
setTimeout($.proxy(function () {
var o = self.options.animationOptions;
var animateOptions = {
content: self.valueDiv,
complete: $.proxy(function () {
self._triggerEvent("progressChanged", self.element.attr("aria-valuenow"), value, false);
}, self),
step: $.proxy(function (ovalue) {
self._performAnimating(ovalue);
}, self),
processValue: percent
}
var animations = $.ui.wijprogressbar.animations;
var duration = o.duration;
var easing = o.animated;
if (easing && !animations[easing]) {
easing = "progress";
}
if (!animations[easing]) {
animations[easing] = function (options) {
this.progress(options, {
easing: easing,
duration: duration || 1000
});
}
}
animations[easing](animateOptions, self.options.animationOptions);

}, self), o.animationDelay);
}
else {
//trigger the progressChanged event.
var oldValue = self.element.attr("aria-valuenow");
self._refreshProgress(percent);
self._triggerEvent("progressChanged", oldValue, value, false);
}
},
       ///Set the label's position of the progress bar.
_setLabelSide: function () {
var self = this;
var fillDirection = self.options.fillDirection;
var labelAlign = self.options.labelAlign;
if (self._isHorizontal()) {
if (labelAlign === "west" || labelAlign === "east" || labelAlign === "center") {
self.label.css("width", self.element.width() 'px');
}
else
if (labelAlign === "running") {
self.label.css("width", "auto");
}
else {
self.element.css("line-height", "normal");
self.valueDiv.css("line-height", "normal");
self.label.css("height", labelAlign === "north" ? self.element.height() 'px' : "auto");
}
}
else {
if (labelAlign === "west" || labelAlign === "east" || labelAlign === "center") {
self.label.css({ "line-height": self.element.height() 'px', "width": self.element.width() 'px' });
}
else
if (labelAlign === "running") {
self.label.css({ "height": "auto", "width": self.element.width() 'px' });
}
else {
self.element.css("line-height", "normal");
self.valueDiv.css("line-height", "normal");
self.label.css("height", labelAlign === "north" ? self.element.height() 'px' : "auto");
}
}
},
       ///get the progress bar's progress orientation.
_isHorizontal: function () {
return this.options.fillDirection === "west" || this.options.fillDirection === "east";
},
    ///start the progress
startTask: function () {
/// Start the progress
if ($(":animated", this.element).length == 0) {
var value = this.value();
this._refreshValue(value);
}
},
       ///stop the progress
stopTask: function () {
/// Stop the progress
this.valueDiv.stop();
},
       //init the progress bar
_initElements: function () {
var self = this;
var o = self.options;
self.element.removeClass("ui-wijprogressbar-west ui-wijprogressbar-east ui-wijprogressbar-north ui-wijprogressbar-south").addClass("ui-wijprogressbar-" o.fillDirection);
var height = self.element.height();
self.valueDiv.css("line-height", "");
self.label.removeClass("lb_west lb_east lb_south lb_north lb_center lb_running").addClass("lb_" o.labelAlign)
.css("line-height", "").css({
left: "",
right: "",
top: "",
bottom: ""
});
if (self._isHorizontal()) {
self.valueDiv.height(height)
.css("line-height", height "px");
}
else {
self.valueDiv.width(self.element.width());
}
self._setLabelSide();
if (self.options.indicatorImage !== "") {
self.valueDiv.css("background", "transparent url(" self.options.indicatorImage ") repeat fixed");
}
},
     ///refresh the progress
_refreshProgress: function (value) {
var self = this;
var ea = new $.Event('progressChanging');
var nowValue = value * (self.max - self.min) / 100 self.min;
var o = self.options;
var cancel = self._triggerEvent("progressChanging", self.element.attr("aria-valuenow"), nowValue, false);
if (cancel) {
return;
}
if (self._isHorizontal()) {
self.valueDiv.toggleClass(o.fillDirection === "east" ? "ui-corner-right" : "ui-corner-left", value === self.max).width(value "%");
}
else {
self.valueDiv.toggleClass(o.fillDirection === "south" ? "ui-corner-bottom" : "ui-corner-top", value === self.max).height(value "%");
}
self.element.attr("aria-valuenow", nowValue);
var txt = self._getFormatString(o.labelFormatString, value);
self._setLabelsText(txt);
var _tooTip = self._getFormatString(o.toolTipFormatString, value);
self.element.attr("title", _tooTip);
},
     ///play progress animation.
_performAnimating: function (obj) {
var self = this;
var len = Math.floor(obj / self.options.indicatorIncrement);
obj = len * self.options.indicatorIncrement;
var o = self.options;
self._refreshProgress(obj);

if (o.labelAlign === "running") {
if (self._isHorizontal()) {
var eleWidth = self.element.width();
var labelWidth = self.label.outerWidth();
var progressWidth = self.valueDiv.outerWidth();
var left = eleWidth === progressWidth ? eleWidth - labelWidth : obj * eleWidth / 100 - labelWidth labelWidth * (eleWidth - progressWidth) / eleWidth;
self.label.css(o.fillDirection === "east" ? "left" : "right", left);
}
else {
var eleHeight = self.element.height();
var labelHeight = self.label.outerHeight();
var progressHeight = self.valueDiv.outerHeight();
var top = eleHeight === progressHeight ? eleHeight - labelHeight : obj * eleHeight / 100 - labelHeight labelHeight * (eleHeight - progressHeight) / eleHeight;
self.label.css(o.fillDirection === "south" ? "top" : "bottom", top);
}
}
},
       //set the label'text
_setLabelsText: function (text) {
if (!this._isHorizontal() && this.options.labelAlign === "rightOrBottom") {
this.label.html('' text '');
return;
}

this.label.html(text);
},
       //format the text
_getFormatString: function (format, val) {
var self = this;
var processValue = parseInt(self.element.attr("aria-valuenow"));
var remainingProcess = self.max - processValue
var percentProgress = val;
var percentageRemaining = 100 - val;
var r = /{0}/g;
format = format.replace(r, processValue.toString());
r = /{ProgressValue}/g;
format = format.replace(r, processValue.toString());
r = /{1}/g;
format = format.replace(r, percentProgress.toString());
r = /{PercentProgress}/g;
format = format.replace(r, percentProgress.toString());
r = /{2}/g;
format = format.replace(r, remainingProcess.toString());
r = /{RemainingProgress}/g;
format = format.replace(r, remainingProcess.toString());
r = /{3}/g;
format = format.replace(r, percentageRemaining.toString());
r = /{PercentageRemaining}/g;
format = format.replace(r, percentageRemaining.toString());
r = /{4}/g;
format = format.replace(r, self.min);
r = /{Min}/g;
format = format.replace(r, self.min);
r = /{5}/g;
format = format.replace(r, self.max);
r = /{Max}/g;
format = format.replace(r, self.max);
return format;
},
     ///위젯을 파괴합니다.
destroy: function () {
this.element.empty()
this.element.removeClass("ui-wijprogressbar ui-widget ui-widget -content ui-corner-all ui-wijprogressbar-h").removeAttr("title");
$.Widget.prototype.destroy.apply(this, 인수);
}
});
 ///진행률 표시줄 애니메이션. 사용자가 맞춤 애니메이션을 작성하려면 애니메이션 옵션을 재정의할 수 있습니다. 그리고 애니메이션을 옵션 키로 설정하세요.
$.extend($.ui.wijprogressbar, {
animations: {
진행: 함수(옵션, 추가) {
options = $.extend({
easing: "swing",
기간: 1000
}, 옵션, 추가);
options.content.stop(true, true).animate({
widthvalue: options.processValue
}, options)
}
}
}); })(jQuery);

위젯은 주로 UI 수준을 다룹니다. 실용적인지 여부는 jQuery의 기존 CSS 프레임워크를 활용해야 알 수 있습니다. themeRoller를 사용하면 스킨을 쉽게 변경할 수 있습니다. 기능에 관해서는 사용자 피드백을 통해 점진적으로 개선될 수 있습니다.
이 진행률 표시줄 자체는 jQuery ui 진행률 표시줄에서 상속되었습니다. 오픈소스이기 때문에 좋은 아이디어만 있으면 필요한 기능을 추가할 수 있습니다.
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software