


Experience 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:
$(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.
//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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

In Elden's Ring, the UI page of this game will be automatically hidden after a period of time. Many players do not know how the UI is always displayed. Players can select the gauge display configuration in the display and sound configuration. Click to turn it on. Why does the Elden Ring UI keep displaying? 1. First, after we enter the main menu, click [System Configuration]. 2. In the [Display and Sound Configuration] interface, select the meter display configuration. 3. Click Enable to complete.

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
