jQuery jQuery.cssHooksMethod

jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Example

Define a new css hook

$(function ($) { //First check whether the jQuery version supports cssHooks if (!$.cssHooks){ //If it is not supported, output an error alert throw(new Error("This feature requires jQuery version greater than or equal to 1.4.3")); } //Wrap it in the DOM document ready event, and write cssHooks at this time to avoid the cssHooks being overwritten elsewhere $(function(){ $.cssHooks.height = { get: function( elem, computed, extra ) { //Handle getting the CSS property },set: function( elem, value ) { //Handle setting the CSS property alert('Perform processing'); } }; $('body').css('height','100%'); }); })(jQuery)

Try it yourself »

Definition and Usage

$.cssHooks provides a way to get and set specific CSS values by defining functions.


Note:1. It is intended to normalize CSS property names or create custom properties.
2. For example, some versions of Webkit-based browsers require the -webkit-border-radius property to set the border-radius of an element, while early Firefox versions use the -moz-border-radius property. A CSS hook can normalize these prefixed properties, allowing .css() to accept a single, standard property name (border-radius, or in DOM property syntax, borderRadius).


Syntax

$.cssHooks


实例

More Examples

Test browser vendor prefix variants
Before normalizing vendor-specific CSS properties, first determine whether the browser supports the standard property or the vendor-prefixed variant.

Define a complete css hook
Define a complete css hook.


jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Other Extensions