X Library Viewer

Download the X Distribution File.

X Short Index

Animation

xAniLine, xAnimation.alphaArc, xAnimation.arc, xAnimation.corner, xAnimation.css, xAnimation.imgSize, xAnimation.line, xAnimation.opacity, xAnimation.para, xAnimation.rgb, xAnimation.rgbByClass, xAnimation.scroll, xAnimation.size, xAnimation.sizeLine, xAnimation, xAniOpacity, xAniRgb, xAniWH, xAniXY, xEllipse, xParaEq, xSequence, xSlideCornerTo, xSlideTo, xWinScrollTo.

DOM

xFirstChild, xFlGet, xFlWrite, xGetElementById, xGetElementsByAttribute, xGetElementsByClassName, xGetElementsByTagName, xLoadLink, xLoadScript, xNextSib, xParent, xParentN, xPrevSib, xSmartLoad, xSmartLoad2, xSmartLoadScript.

Debug

xConsole, xEditable, xName, xParentChain, xSetIETitle.

Event

xAddEventListener, xAddHandlers, xDragInFence, xEnableDrag, xEnableDrop, xEvent, xHttpRequest, xPreventDefault, xRemoveEventListener, xStopPropagation.

Image

xImgAsyncWait, xImgRollSetup, xTriStateImage.

Iteration

xEach, xEachE, xEachN, xEachUntilReturn, xTimes, xWalkToFirst, xWalkToLast, xWalkTree, xWalkTree2, xWalkTree3, xWalkTreeRev, xWalkUL.

Misc

xCookie, xDef, xDeg, xGetURLArguments, xInA, xLibrary, xLinearScale, xNum, xRad, xRound, xStr.

Position

xCardinalPosition, xCen, xCenter, xGetEleAtPoint, xHasPoint, xIntersection, xLeft, xMoveTo, xOffset, xPageX, xPageY, xScrollLeft, xScrollTop, xTop.

Size

xClientHeight, xClientWidth, xClip, xColEqualizer, xDocSize, xHeight, xResizeTo, xWidth.

String

xCamelize, xCapitalize, xHex, xJoin, xPad, xParseColor, xRgbToHex, xSplit, xStrEndsWith, xStrRepeat, xStrReplaceEnd, xStrStartsWith, xTrim.

Style

xAddClass, xDisplay, xFindAfterByClassName, xFindBeforeByClassName, xGetComputedStyle, xGetCSSRules, xGetStyleSheetFromLink, xHasClass, xHasStyleSelector, xHasStyleSheets, xInsertRule, xOpacity, xRemoveClass, xStyle, xTagStyle, xToggleClass, xTraverseDocumentStyleSheets, xTraverseStyleSheet.

Table

xTable, xTableCellVisibility, xTableColDisplay, xTableCursor, xTableCursor2, xTableHeaderFixed, xTableIterate, xTableRowDisplay, xTableSync.

UI

xBar, xCalendar, xCollapsible, xDialog, xFenster, xMenu1, xMenu1A, xMenu1B, xMenu5, xMenu6, xModalDialog, xPersistentDisplay, xPopup, xSelect, xSplitter, xTabPanelGroup, xTextArea, xTooltipGroup.

Window

xWinClass, xWindow, xWinOpen.

X Long Index

Animation

xAniLine
Animate an element's position over a line segment.
xAnimation.alphaArc
Animate an element's opacity and its position over an elliptical arc. This is an xAnimation method.
xAnimation.arc
Animate an element's position over an elliptical arc. This is an xAnimation method.
xAnimation.corner
Animate an element's corner over a line segment. This is an xAnimation method.
xAnimation.css
Animate an element's CSS property that accepts integer pixel values. This is an xAnimation method.
xAnimation.imgSize
Animate an image's width and height. This is an xAnimation method.
xAnimation.line
Animate an element's position over a line segment. This is an xAnimation method.
xAnimation.opacity
Animate an element's opacity. This is an xAnimation method.
xAnimation.para
Animate an element's position over parametric equations. This is an xAnimation method.
xAnimation.rgb
Animate an element's CSS property that accepts color values. This is an xAnimation method.
xAnimation.rgbByClass
Animate a CSS property that accepts color values, for all elements with the given className. This is an xAnimation method.
xAnimation.scroll
Animate the scroll position of a window or element. This is an xAnimation method.
xAnimation.size
Animate an element's width and height. This is an xAnimation method.
xAnimation.sizeLine
Perform a sequence of animations of an element's position and size. This is an xAnimation method.
xAnimation
Using xAnimation is easy. Create an xAnimation object and call one of the animation methods. You can then use the pause/resume methods. The other methods and properties are documented here to help you write your own animation methods. xAnimation provides an animation "engine" which supports unlimited axes of animation, multiple acceleration types and an onEnd handler. The onEnd handler can return true to cause the animation to repeat. It supports a bounce-back feature. Acceleration is implemented as an array of functions so it is easy to add custom acceleration types.
xAniOpacity
Animate an element's opacity.
xAniRgb
Animate an element's CSS property that accepts color values.
xAniWH
Animate an element's size. This is a minimal, time-based implementation - only supports constant velocity.
xAniXY
Animate an element's position over a line segment. This is a minimal, time-based implementation - only supports constant velocity.
xEllipse
Animate an element along an elliptical path.
xParaEq
Parametric Equation Animation. X(t) and Y(t) are expressions that generate the x and y coordinates during the slide. These expressions are evaluated with the javascript eval() function. Within the expression you may use any valid sub-expression that eval allows and that is in scope. For example, you may call methods of the Math object such as Math.sin(), Math.cos(), and Math.tan(). You may also reference any global variables or functions. One variable that is within scope for your expression is the parameter t. That is, t is the argument to the equations you provide. At each iteration, the variable t increments by .008 (default value). The Time argument to parametricEquation() specifies the total time for the slide in milliseconds. If the value is zero, the slide will not timeout. You can stop any slide, at any time, by this assignment: element.stop = true;. The values from your expressions are plotted on a coordinate system with it's origin at the center of the sliding element's container. The coordinates are then translated by the element's container's scrollLeft and scrollTop values. So the animation will remain visible if the user scrolls or resizes the element's container.
xSequence
xSequence is an experiment with time and event based sequences.
xSlideCornerTo
Time-based resize (corner slide) with sinusoidal rate.
xSlideTo
Animated, linear motion with sinusoidal or linear rate. Slide the element to the target position in the given time.
xWinScrollTo
Scroll a window to a point with sinusoidal or linear rate.

DOM

xFirstChild
An enhanced wrapper for element.firstChild.
xFlGet
Returns a reference to a Flash object or null if not found.
xFlWrite
Write Flash HTML into the document.
xGetElementById
Get an object reference to the element object with the passed ID.
xGetElementsByAttribute
Return an array of all sTag elements whose sAtt attribute matches sRE. sAtt can also be a property name but the property must be of type string.
xGetElementsByClassName
Returns an array of elements which are descendants of parentEle and have tagName and clsName. If parentEle is null or not present, document will be used. If tagName is null or not present, "*" will be used.
xGetElementsByTagName
Returns an array of elements which are descendants of parent and have tagName. If parent is null or not present, document will be used. If tagName is null or not present, "*" will be used.
xLoadLink
Dynamically create a LINK element and append it to the HEAD.
xLoadScript
Dynamically load a js file.
xNextSib
Get an element's next sibling which has a specific tagName.
xParent
Returns the nearest ancestor of ele whose nodeName == name. Assumes name is lowercase. Omit name to get the first ancestor.
xParentN
Returns e when n == 0, e.parentNode when n == 1, e.parentNode.parentNode when n == 2, etc.
xPrevSib
Get an element's previous sibling.
xSmartLoad
Load script or style sheet if not loaded before.
xSmartLoad2
Create any number of script or link elements and assign a URL to each.
xSmartLoadScript
Maintains an array of loaded urls to prevent the same Url being loaded twice.

Debug

xConsole
A debugging utility.
xEditable
A simple function to allow in-line editing.
xName
Debugging utility.
xParentChain
Walks up the parent chain building a string suitable for displaying.
xSetIETitle
Debugging utility for running multiple versions of IE. Prepend browser version to document title.

Event

xAddEventListener
Register an event listener on the element.
xAddHandlers
Assign DOM0 event handlers. For each N do: xGetElementById(idN)[ev] = fnN
xDragInFence
Enable dragging for the element. Optionally, dragging can be limited to a rectangular area. If fnDrag is not provided then this code will provide basic dragging. If fnDrag is provided then it must implement the dragging. See xEnableDrag for more info.
xEnableDrag
Enable dragging for the element. If fnDrag is not provided then this code will provide basic dragging. If fnDrag is provided then it must implement the dragging.
xEnableDrop
Enable an element to receive a drop event from any element drag-enabled with xEnableDrag.
xEvent
Resolve browser differences for event properties. This is an object prototype. Create an instance with the 'new' operator.
xHttpRequest
An asynchronous HTTP request object. Features a 'timeout' event, an optional random parameter to prevent caching, detailed error reporting, a 'busy' property for serialization, and more.
xPreventDefault
A cross-browser wrapper for event.preventDefault
xRemoveEventListener
Unregister an event listener previously registered with xAddEventListener.
xStopPropagation
A cross-browser wrapper for event.stopPropagation

Image

xImgAsyncWait
Asynchronously waits (and monitors the status) of newly created or static images. Can be called before or after window.onload, or in the HTML following the last IMG element. During monitoring of image load status, your status function will be called at each iteration. After all images successfully load, your app initialization function is called. If any image fails to load, your error function is called. You can provide error and abort images for those that fail to load.
xImgRollSetup
Image rollover setup. Can not be called before the window onload event. Pass image IDs starting with 4th argument. The only html requirement is for each IMG tag to have an ID. Assumes this image file naming convention: out img = path + imgEleId + fileExt over img = path + imgEleId + ovrSuffix + fileExt
xTriStateImage
Image rollover with a third state - mousedown.

Iteration

xEach
Access each element of a collection sequentially (by its numeric index) and do something with it.
xEachE
For each ele/id, call the callback function passing it the element object and the count. Pass any number of ele/id's as arguments - the callback function must be the last argument.
xEachN
Iterate over all elements with the same sIdPrefix and a sequential, numeric suffix beginning with iStart. fnCallback is called for each element and passed the element, its numeric suffix and oData.
xEachUntilReturn
Access each element of a collection sequentially (by its numeric index) and do something with it. Stop when the called function returns a value.
xTimes
Call a function n times.
xWalkToFirst
Starts from a node and applies fnVisit up to the very first element (or up to a non-null returned value from 'fnVisit'). Children of starting node are not processed since children are consider to be "after" their parent. Optional 'data' and 'skip' work like in xWalkTree2.
xWalkToLast
Starts from a node and applies 'fnVisit' up to the very last element (or up to a non-null returned value from 'fnVisit'). Children of starting node are processed since children are consider to be "after" their parent (this is the opposite to xWalkToFirst). Optional 'data' and 'skip' work like in xWalkTree2.
xWalkTree
Perform a preorder traversal on the subtree starting at oNode and pass each Element node to fnVisit.
xWalkTree2
Traverse a sub-tree.
xWalkTree3
Perform a preorder traversal on the subtree starting at oNode and pass each Element node to fnVisit.
xWalkTreeRev
Traverse a sub-tree in reverse.
xWalkUL
Perform a preorder traversal on nested ULs starting at oUL. If there is a nested UL it must be a direct child of the LI (not neccessarily the first). Only supports having one nested UL in each LI. The callback function is called for every LI.

Misc

xCookie
Set, get or delete a cookie name/value.
xDef
Determine if all arguments are 'defined'.
xDeg
Converts from radians to degrees.
xGetURLArguments
Parses the name/value pairs on the url.
xInA
Return the array index of the element which is === v, else return false if v is not in a.
xLibrary
The version property of this object gives the X Library version string for the distribution in which this file was included. Each X symbol's XML file documents its own revisions. This file (xlibrary.xml) will have summary notes for each X release.
xLinearScale
Get a scaled value
xNum
Determine if the arguments are of type Number.
xRad
Converts from degrees to radians.
xRound
Rounds a number to the specified number of decimal digits.
xStr
Determine if all arguments are of type 'string'.

Position

xCardinalPosition
A convient way to get the coordinates of an element's 'cardinal' (or 'compass') points.
xCen
Center an absolute-positioned element.
xCenter
Center a positioned element within the current client window space. If w,h not specified, then the existing width and height of e are used.
xGetEleAtPoint
Returns a reference to the element with the highest z-index which contains the given absolute point.
xHasPoint
Determines if an element contains an absolute point. The element's boundary is extended (negative clip), or contracted (positive clip) by the clipping parameters.
xIntersection
Determine if two elements intersect and if so determine the intersecting rectangle.
xLeft
Return and optionally set the element's x coordinate.
xMoveTo
Set the element's x and y coordinates.
xOffset
Return an object with x and y properties giving the offset position of child relative to parent.
xPageX
Get the page-relative X position of the element.
xPageY
Get the page-relative Y position of the element.
xScrollLeft
Determine how far the window (or an element) has scrolled horizontally.
xScrollTop
Determine how far the window (or an element) has scrolled vertically.
xTop
Return and optionally set the element's y coordinate.

Size

xClientHeight
The inner height of the window not including any scrollbar - that is, the "viewport".
xClientWidth
The inner width of the window not including any scrollbar - that is, the "viewport".
xClip
Set the element's clipping rectangle. If ele is the only argument then set clip to existing width and height.
xColEqualizer
Equalize the heights of any number of columns. Pass any number of pairs of elements to this function.
xDocSize
Determines the (largest) width and height of the 'document'.
xHeight
Return and optionally set the element's height. It attempts to return and/or set the equivalent of offsetHeight. xHeight provides, effectively, a read/write version of offsetHeight. The border is included, as well as the padding, in the calculations. When returning the existing height, xHeight returns offsetHeight, which is the sum of the border, padding and style.height values. When setting a new height, xHeight finds the current border and padding values of the element and then subtracts those from the height you have specified before assigning the result to style.height.
xResizeTo
Resize an element.
xWidth
Return and optionally set the element's width. It attempts to return and/or set the equivalent of offsetWidth. xWidth provides, effectively, a read/write version of offsetWidth. The border is included, as well as the padding, in the calculations. When returning the existing width, xWidth returns offsetWidth, which is the sum of the border, padding and style.width values. When setting a new width, xWidth finds the current border and padding values of the element and then subtracts those from the width you have specified before assigning the result to style.width.

String

xCamelize
Converts a CSS property name string (dash-separated) to a camel-cased string (style object property name).
xCapitalize
Capitalize the first letter of every word in str.
xHex
Converts an integer to a hex string.
xJoin
Serialize an object. Reverse the operation with xSplit.
xPad
Pad a string, on the left or right, to a specific length using a specific character.
xParseColor
Parse a color string or number into its components.
xRgbToHex
Converts three numbers (representing RGB colors) to a hex string in the form "#RRGGBB".
xSplit
Split str on delim1 then split each substring on delim2. Create an object and add properties where the property name is on the left of delim2 and its value is on the right of delim2. Reverse the operation with xJoin.
xStrEndsWith
Returns true if s ends with end.
xStrRepeat
Repeat a string.
xStrReplaceEnd
Replaces newEnd.length characters at the end of s with newEnd.
xStrStartsWith
Returns true if s begins with beg.
xTrim
Removes leading and trailing white-space from a string.

Style

xAddClass
Adds a class name to an element.
xDisplay
A safe wrapper for element.style.display.
xFindAfterByClassName
Finds the first element after the given one that is from a given class.
xFindBeforeByClassName
Finds the first element before the given one that is from a given class.
xGetComputedStyle
A safe wrapper for getComputedStyle and currentStyle.
xGetCSSRules
Extracts CSS rules from the style sheet object (IE vs. DOM CSS level 2).
xGetStyleSheetFromLink
Extracts style sheet object from the HTML LINK object (IE vs. DOM CSS level 2).
xHasClass
Returns true if an element has a specified class name
xHasStyleSelector
Checks whether any of the stylesheets attached to the document contain the definition of the specified style selector (simple string matching at the moment).
xHasStyleSheets
Checks browser support for stylesheet related objects (IE or DOM compliant).
xInsertRule
Insert a new rule into a styleSheet.
xOpacity
Set or get the opacity of an element.
xRemoveClass
Removes a class name from an element
xStyle
Set any style property for any number of elements. If an exception is thrown, and sProp=='display', and the browser is IE7 or down, and the element is one of the table elements, then assign 'block' or 'inline' based on tagName.
xTagStyle
Set any style property for any number of tags.
xToggleClass
Toggles a class name on or off for an element
xTraverseDocumentStyleSheets
Traverses all stylesheets attached to a document (linked as well as internal).
xTraverseStyleSheet
Traverses all rules in the stylesheet, calling callback function on each rule. Recursively handles stylesheets imported with @import CSS directive. Stops when the callback function returns true (it has found what it's been looking for).

Table

xTable
This is an unobtrusive table enhancement. It freezes the table's first row (or THEAD) and first column while the rest of the table is scrollable. If the table has a CAPTION it is removed and inserted above the frozen header.
xTableCellVisibility
Set the visibility of a table cell.
xTableColDisplay
Set the display of a table column.
xTableCursor
Mouseover highlight on rows and cells.
xTableCursor2
Mouseover highlight on rows and cells. Click to select a cell.
xTableHeaderFixed
xTableHeaderFixed is an unobtrusive table enhancement. It makes a copy of a table's THEAD section. While the table is visible in its container the THEAD copy will be fixed to the top of the container, so you can scroll up and down in a long table and the header will always be visible. The container can be a window or a scrollable element. The position and size of the THEAD copy will be adjusted when the window is resized. The THEAD copy is clipped to its container's inner width. You only need to instantiate one xTableHeaderFixed object for each group of tables that have the same styling - and so those tables should have a common className, which you pass to the constructor. You must assign all of the table's styles relative to this className so that the THEAD copy will be styled just like it. It takes the widths of all THs (not TDs) in the THEAD and assigns them to the corresponding THs in the THEAD copy. When instantiating, you do not have to keep a reference to the object - it keeps a reference to itself, but if you plan on calling the 'init' or 'paint' methods later then you'll need to keep a reference to the object.
xTableIterate
Iterates thru all rows and cols of a table and calls fnCallback for each.
xTableRowDisplay
Sets the display of a table row.
xTableSync
Assign a function to handle events which occur on either table and access corresponding TDs.

UI

xBar
Bar-Graph Object
xCalendar
xCalendar is a popup date-picker. It restricts selection to a range of Dates. Days outside the range are greyed-out. Only days in-range have a mouseover effect and can be selected. If you don't set a range it will default to the current year. When the user selects a date, a date string will be assigned to the input element you specify with the 'setInput' method. When the calendar is shown, it is positioned just to the right of this element. While displayed, the user can cancel the calendar by pressing ESCape or clicking anywhere outside the calendar. If you call xCalendar's 'show' method from a click listener then you should call xStopPropagation to prevent xCalendar from being canceled immediately.
xCollapsible
Creates a collapsible list from nested ULs or nested DIVs. A UL/DIV is a "target" - it will have its display toggled when its "trigger" is clicked (except for the outermost UL/DIV). For ULs the trigger is the UL's previous sibling element. For DIVs the trigger is also the DIV's previous sibling element, but it must be a heading element (H1, H2, etc.).
xDialog
Provides a dialog box framework.
xFenster
xFenster takes an existing DIV or IFRAME element and dynamically encloses it in a draggable, resizeable "window" (fenster). If the DIV or IFRAME does not exist xFenster will create it. The constructor takes a single object as an argument. The properties of this object are documented below in the "Parameters" section.
xMenu1
xMenu1 Object Prototype
xMenu1A
xMenu1A Object Prototype. A variation on xMenu1. The menu slides down and up.
xMenu1B
xMenu1B Object Prototype. A variation on xMenu1A. The menu requires a click to close and opening one closes any others that were open.
xMenu5
Only one branch per level can be open. Assumes btnClass element to be a direct child of an LI, tho it doesn't have to be the first child. Assumes the btn's corresponding UL to be a sibling, tho it doesn't have to be the next sibling.
xMenu6
A UL-based menu with unlimited levels and many other features.
xModalDialog
A simple modal dialog box object.
xPersistentDisplay
xPersistentDisplay provides persistent display or non-display of elements with specific CSS class names.
xPopup
A DHTML alternative to popup windows.
xSelect
Accessible Categories and Sub-Categories. xSelect is another experiment in unobtrusive DHTML. xSelect implements categories and sub-categories as two SELECT controls where the contents of the second control dynamically change depending on the selection in the main control. In your HTML create a SELECT element (which I'll call s0) which contains OPTGROUP elements. Within each OPTGROUP are any number of OPTION elements. Given the id of s0, xSelect creates two SELECT elements: The 'main category' SELECT (s1) contains an OPTION for each OPTGROUP in s0. The 'sub-category' SELECT (s2) is dynamically filled with OPTGROUP OPTIONs depending on which category is selected in s1. s1 and s2 are dynamically created and appended to the same form which contains s0. s0 is hidden, s1 is positioned where s0 was, and s2 is positioned below or to the right of s1. If the browser doesn't support the objects required by xSelect, or if the user has javascript disabled, then the user will get the original SELECT which contains all main categories (as OPTGROUPs) and all sub-categories (as OPTIONs within each OPTGROUP).
xSplitter
This object is a nestable, dual-pane splitter. It can be horizontal or vertical. Each xSplitter has two panes. Pane1 is the left (or top) pane, and pane2 is the right (or bottom) pane. An xSplitter can be nested inside any pane of any other xSplitter. xSplitter makes no assumptions about classnames or id strings - the only requirement is that the xSplitter DIV contain 3 child DIVs in this order: pane1, pane2, and dragBar.
xTabPanelGroup
Downgradeable, accessible, tabbed panels.
xTextArea
A wrapper around an html textarea allowing manipulation of its contents using normal javascript string methods.
xTooltipGroup
Different tooltips applied to groups of elements.

Window

xWinClass
An unobtrusive version of xWindow
xWindow
xWinOpen
A simple alternative to xWindow.

xTop

Description

Return and optionally set the element's y coordinate.

Syntax

xTop(ele[, iY])

Parameters

eleid string or object reference
iYinteger y coordinate

Return

integer

Source

// xTop r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xTop(e, iY)
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=xGetComputedStyle(e,'top',1);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  return iY;
}

Dependencies

xGetElementById, xGetComputedStyle, xDef, xStr, xNum

Demos

toys - Index of all X demos.

Revisions

2: 26Oct06If ele.style.top=="" then use xGetComputedStyle.
1: 31Mar04put in it's own file for use with XC

License

By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.

Tech Support

Forum support is available at the X Library Support Forums.

About Cross-Browser.com

Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.

Search

Cross-Browser.com

World Wide Web

User Projects

If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.