First, write down the basic Yui class:YAHOO.util.Dom
I. Positioning Elements
var pos = YAHOO.util.Dom.getXY("id1");YAHOO.util.Dom.setXY("id2",pos);
Similarly, there are setx, sety, and other methods.
Ii. Set styles
YAHOO.util.Dom.setStyle(["id1","id2"],"opacity","0.5");YAHOO.util.Dom.getStyle("id2","opacity")';
The first action sets the transparency of id1 and Id2 to 0.5, and the second action gets the transparency value of Id2.
Note: earlier versions of opera 9 do not support opacity transparency;
In addition, this example also demonstrates how to call multiple elements in a request.[“element1”,“element2”]
.
3. Obtain the window size
var viewport = [YAHOO.util.Dom.getViewportWidth();YAHOO.util.Dom.setViewportHeight();]
ObtainCurrent visible sizeNot the absolute physical size.
Iv. Manage styles
Yui has multiple style management methods.
-
Getelementsbyclassname (classname, tagname, rootnode)
-
Returns an array of elements with the specified style name. You can narrow the search scope by specifying the root node (parent node) Name.
-
Hasclass (element, classname );
-
Determines whether an element has a style. The return value is true or false.
-
Addclass (element, classname );
-
Add a style;
-
Removeclass (element, classname );
-
Remove existing styles;
-
Replaceclass (element, oldclassname, newclassname)
-
Replace the old style with the new one;
Example: var element = Yahoo. util. Dom. getelementsbyclassname ("red", "Div ")
This is the set of Div for getting class = "red.
In addition, the class name function for getting an element in Yui is Yahoo. util. Dom. Get ("ID"). classname.
Find a similar online article: Translation: Yui Dom collection