/// <summary>Retrieves the border outline size for the given element (if it's border styles are specified in pixels).</summary> /// <param name="element">The element to examine.</param> public static Spacing GetPixelBorder(jQueryObject element) { // Setup initial conditions. Spacing value = new Spacing(); if (Script.IsNullOrUndefined(element)) return value; // Retrieve each edge. value.Left = GetBorderEdge(element, Edge.Left); value.Top = GetBorderEdge(element, Edge.Top); value.Right = GetBorderEdge(element, Edge.Right); value.Bottom = GetBorderEdge(element, Edge.Bottom); // Finish up. return value; }
/// <summary>Sets the top position of an element so it is vertically centered within another element.</summary> /// <param name="element">The element to vertically center.</param> /// <param name="within">The element to center within.</param> /// <param name="offset">The offset to take into account when calculating position.</param> public static jQueryObject CenterVertically(jQueryObject element, jQueryObject within, Spacing offset) { int top = (within.GetHeight() / 2) - (element.GetHeight() / 2); if (!Script.IsNullOrUndefined(offset)) { top += offset.VerticalOffset; } element.CSS(Top, top + "px"); return element; }
/// <summary>Sets the left and top position of an element so it is centered within another element.</summary> /// <param name="element">The element to center.</param> /// <param name="within">The element to center within.</param> /// <param name="offset">The offset to take into account when calculating position.</param> public static jQueryObject Center(jQueryObject element, jQueryObject within, Spacing offset) { CenterHorizontally(element, within, offset); CenterVertically(element, within, offset); return element; }
/// <summary>Sets the left position of an element so it is horizontally centered within another element.</summary> /// <param name="element">The element to horizontally center.</param> /// <param name="within">The element to center within.</param> /// <param name="offset">The offset to take into account when calculating position.</param> public static jQueryObject CenterHorizontally(jQueryObject element, jQueryObject within, Spacing offset) { int left = (within.GetWidth() / 2) - (element.GetWidth() / 2); if (!Script.IsNullOrUndefined(offset)) { left += offset.HorizontalOffset; } element.CSS(Left, left + "px"); return element; }
/// <summary>Copies the values from the given Spacing object.</summary> /// <param name="spacing">The object to copy from.</param> public void CopyValues(Spacing spacing) { Left = spacing.Left; Top = spacing.Top; Right = spacing.Right; Bottom = spacing.Bottom; }