search
HomeWeb Front-endJS TutorialExperience in developing Widgets based on jQuery UI CSS Framework_jquery

The two core css files in jQuery UI are ui.core.css and ui.theme.css. These two css styles run through the entire jQuery ui-based interface, and you can generate your own styles through jQuery ui ThemeRoller.
.ui-helper-hidden: Apply display:none to the element
.ui-helper-hidden-accessible: Set the absolute position of the element to invisible
.ui-helper-clearfix: Applies to floats Attributes that wrap the parent element
. ui-helper-zfix: Suitable for fixing the problem of iframe element coverage
.ui-state-default: The default style of the element
.ui-state-hover: The element is hover State style
.ui-state-focus: Style when the element is in the focus state
.ui-state-active: Style when the element is in the active state (usually selected by the mouse)
.ui-state-hightlight :Styles that need to highlight the state
.ui-state-error:Styles whose elements are error states (generally describing error information)
.ui-state-error-text:Styles that describe error text
. ui-state-disabled: The style of the element being disabled
.ui-priority-primary: Applied to the first-level button, if the button needs to be distinguished from Zengji. Bold font will be applied
.ui-priority-secondary: is applied to the button with the second level. Corresponding to the previous scenario, a normal thickness font will be applied and is slightly transparent relative to the element
Icon types: css framework provides a set of default icons. These icons are suitable for most scenarios. The generally used method is "ui-icon ui-icon-****" to specify icon
.ui-corner-tl :The upper left corner is rounded, based on css3, IE does not support
.ui-corner-tr: The upper right corner is rounded, based on css3, IE does not support
.ui-corner-bl: The lower left corner is rounded, based on css3 , IE does not support
.ui-corner-br: The lower right corner is rounded, based on CSS3, IE does not support
.ui-corner-top: The top two corners are rounded, based on CSS3, IE does not support
.ui-corner-bottom: The bottom two corners are rounded, based on css3, IE does not support
.ui-corner-right: The two right corners are rounded, based on css3, IE does not support
.ui -corner-left: The two left corners are rounded, based on CSS3, IE does not support
.ui-corner-all: All corners are rounded, based on CSS3, IE does not support
.ui-widget-overlay: Mask
.ui-widget-shadow:Shadow
When writing jQuery ui widget, you can make a custom UI compatible with jQuery ui theme by appropriately using these css.
jQuery ui provides some basic widgets, but it provides a good mechanism to create widgets. The jQuery css framework contains basic css styles (visual and sensory such as color, font size, icons, etc.), while in the ui css, you need to define the css that builds the widget structure, such as margin, padding, position, etc. When developing widgets, you should also try to follow this principle, so that you can make good use of jquery theme roller to apply styles and maintain consistency overall. In the previous article, we briefly introduced jquery css framework. The following is a brief introduction to the development guidelines of jquery ui.
Jquery’s official documentation writes this very clearly. Generally speaking, jquery ui inherits from the jquery.ui.widget.js file. This file provides a factory method to create widget objects. The method is $.widget(String name, Options prototype). The following is a brief introduction to the methods and properties provided by this class. These will be overridden when the widget is created.
destroy(): Remove the widget instance from the dom object. This method is generally necessary when developing widgets. It is to remove the styles and behaviors and dom structure you added on the dom element
options: What is saved here is the configuration information of the widget. When creating the widget, you need to set some configuration parameters.
element: It is the DOM object that the widget acts on.
enable() and disable(): These two methods are to disable and enable widgets. In fact, it is to modify options.disabled.
There are also two private methods that need to be overridden when creating a widget. In widgets, all private methods will be prefixed with "_".
_create(): This method is the method to create a widget. When the page calls the widget, this method will be executed to build the widget. Most of the Widget's behavior and structure are created here.
_init(): This method will not be overridden most of the time. This method is executed after _create when building the widget.
From the relevant documents:
_create(): The method is executed when the widget is built, and the _init() method is executed when the widget is built and re-initialized. The destroy method is executed when the widget is removed.
_setOption(): This method provides the setting of attributes of options. Generally, if the parameters in options do not require special processing (verification, type conversion, and triggering an operation when setting attributes, etc.) This method needs to be overridden.
The following code illustrates the difference between the _create() method and the _init() method:

Copy code Code As follows:

$(function(){
// _create() and _init() are executed when called for the first time
$("div").mywidget();
// The widget has been instantiated on the div. At this time, only the _init() method is executed
$("div").mywidget();
// Destroy the widget
$("div" ).mywidget("destroy");
// Because the widget has been destroyed, both the _create() and _init() methods will be executed at this time
$("div").mywidget();
});

Event
If there is a custom event, you can use the method _trigger() encapsulated by the widget for us to handle it. The calling method is this._trigger( type, event, data), the first parameter is the time type, the second parameter is the event object, and the third parameter is the parameter to be passed for the event.

Next, I will use a simple jquery ui widget code to illustrate how to develop a widget.
Copy code The code is as follows:

//This widget modifies the textbox. It does not have css itself, but uses the style of jquery ui css framework
(function($){
//UI defaults to jquery's ui prefix, followed by the widget name
$.widget("ui. textboxdecorator", {
//There are no options in this widget
options:{
},
_init: function(){
//Verify whether it is an element that needs to be decorated
if (!(this.element.attr("tagName").toLowerCase() === "input" || this.element.attr("tagName").toLowerCase() === "textarea")) {
return;
}
if (!(this.element.attr("type").toLowerCase() === "text" || this.element.attr("type").toLowerCase() === "password")) {
if (this.element.attr("tagName").toLowerCase() === "input")
return;
}
//this .element is the element that calls this widget
var e = this.element;
//ui-widget The basic style of the widget, ui-state-default, the default state style; ui-corner-all rounded corners. (Based on css3, does not work under IE)
this.element.addClass("ui-widget ui-state-default ui-corner-all");
//Add hover effect and active effect
this.element.mouseover(function(){
e.addClass("ui-state-hover");
}).mouseout(function(){
e.removeClass("ui-state- hover");
}).mousedown(function(){
e.addClass("ui-state-active");
}).mouseup(function(){
e.removeClass ("ui-state-active");
});
},
//When destroyed, remove the style added by the widget
destroy:function(){
this.element .removeClass("ui-widget ui-state-default ui-corner-all ui-state-hover ui-state-active");
}
})
})(jQuery)

When using this widget, you need to reference jquery, jquery.ui.core.js, jquery.ui.widget.js files, and css files need jquery.ui.core.css and jquery.ui.theme The two .css files
use $("***"). textboxdecorator(); when calling this widget.
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
The Origins of JavaScript: Exploring Its Implementation LanguageThe Origins of JavaScript: Exploring Its Implementation LanguageApr 29, 2025 am 12:51 AM

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

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

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment