Element based functions.
Members
-
<static> Events :Arrays
-
Stored Element Events.
Type:
- Arrays
Methods
-
<static> $q(selector)
-
Returns a DOM element.
Parameters:
Name Type Description selectorString The DOM selector.
Returns:
- Type
- HTMLElement
-
<static> $qAll(selectors)
-
Returns an array of DOM ellements.
Parameters:
Name Type Description selectorsString Selectors to find in the DOM.
Returns:
- Type
- Array
-
<static> addClass(elem, classN)
-
Adds a class name to the element passed.
Parameters:
Name Type Description elemHTMLElement The element to add a class name to.
classNString The class name to add.
-
<static> clean(node)
-
Returns an element without whitespace.
Parameters:
Name Type Description nodeHTMLElement The element to remove whitespace from.
Returns:
- Type
- HTMLElement
-
<static> clicked(evt)
-
Returns element that was clicked.
Parameters:
Name Type Description evtEvent The event object.
Returns:
- Type
- HTMLElement
-
<static> collides(arg1, arg2)
-
Returns
trueorfalseif an element collides with another one.Parameters:
Name Type Description arg1HTMLElement | Object Element to detect collision or object with coordinates.
arg2HTMLElement | Object Second element to detect collision or object with coordinates.
Returns:
- Type
- Boolean
Example
var elem1 = ML.El.$('test-elem-1'); var elem2 = {width: 100, height: 300, x: 0, y: 200}; // You can also pass in an var collides = ML.El.collides(elem1, elem2); // object of coordinates. // i.e. width, height, x and y. if (collides) { console.log('Elements are colliding.'); } else { console.log('No collision detected.') } -
<static> create(element [, attrs])
-
Returns an element to be created in the DOM with attributes passed.
Parameters:
Name Type Argument Description elementHTMLElement The tag to create, i.e.
div.attrsObject <optional>
Attributes to add to tag.
Returns:
- Type
- HTMLElement
Example
// NOTE: When setting class name make sure to put in quotes, see example: var div = ML.El.create('div', {'id': 'test-elem', 'class': 'cool-div'}); -
<static> cssTransform(el, values)
-
Applies CSS transform to an element.
Parameters:
Name Type Description elHTMLElement Element to apply style to.
valuesString The CSS transform values to apply.
-
<static> cssTransition(el, values)
-
Applies a CSS transition to an element.
Parameters:
Name Type Description elHTMLElement Element to apply style to.
valuesString The css transition values to apply.
-
<static> customEventTrigger(name, data [, el])
-
Create a custom event.
Parameters:
Name Type Argument Default Description nameString The name of the custom event.
dataObject Data to send with the custom event.
elHTMLElement <optional>
document Element to attach the custom event to.
-
<static> data(element, attr)
-
Returns a data attribute.
Parameters:
Name Type Description elementHTMLElement The element to get the data attribute value for.
attrString The data attribute, excluding
data-.Returns:
- Type
- String | Number
-
<static> dimens(elem)
-
Returns the width, height, x and y position of an element.
Parameters:
Name Type Description elemHTMLElement The element's dimensions.
Returns:
- Type
- Object
-
<static> evt(el, type, cb [, capture])
-
Event listener bound to elements.
Parameters:
Name Type Argument Default Description elHTMLElement The element to bind an event to.
typeString The type of event.
cbfunction Callback function.
Properties
Name Type Description eEvent The Event Object.
captureBoolean <optional>
false -
<static> findParent(el, tag, classN)
-
Returns parent element specified. Returns false if element is not found.
Parameters:
Name Type Description elHTMLElement The child element to search for ancestor elements.
tagString Name of tag to search for.
classNString Class name of the tag to search for.
Returns:
- Type
- HTMLElement | Boolean
-
<static> getAttr(element, attr)
-
Returns attribute value for passed attribute.
Parameters:
Name Type Description elementHTMLElement The element to get the attribute value for.
attrString The attribute to get a value from.
Returns:
- Type
- String | Number
-
<static> getStyle(element, styleProp)
-
Returns a style for a specific element.
Parameters:
Name Type Description elementHTMLElement The element to get styles for.
stylePropString Style property to get the value of.
Returns:
- Type
- Object
-
<static> hasClass(elem, classN)
-
Returns
trueorfalseif an element has a specific class name.Parameters:
Name Type Description elemHTMLElement Element to check if it has a specific class name.
classNString The class name to check for.
Returns:
- Type
- Boolean
-
<static> isBound(node, type, funcName)
-
Returns
trueorfalseif an event is bound to an element.Parameters:
Name Type Description nodeHTMLElement The HTML element to track.
typeString The type of event, i.e.
click,focusetc...funcNameString The name of the function bound to the element.
Returns:
- Type
- Boolean
-
<static> position(elem)
-
Returns the x and y position of an element.
Parameters:
Name Type Description elemHTMLElement The element's x and y position.
Returns:
- Type
- Object
-
<static> removeClass(elem, classN [, multiple])
-
Removes a class name from an element.
Parameters:
Name Type Argument Default Description elemHTMLElement The element of the class name to be removed.
classNString Class name(s) to be removed.
multipleBoolean <optional>
false If there are multiple class names to be removed.
-
<static> removeEvt(el, type, cb [, capture])
-
Remove event listener bound to an element.
Parameters:
Name Type Argument Description elHTMLElement The element to remove the event from.
typeString The type of event.
cbfunction Callback function.
Properties
Name Type Description eEvent The Event Object.
captureBoolean <optional>
-
<static> setStyles(element, props)
-
Styles an element.
Parameters:
Name Type Description elementHTMLElement The element to set styles to.
propsObject Style properties and values.
-
<static> toggleClass(elem, classN [, cond])
-
Toggles the class name of an element.
Parameters:
Name Type Argument Description elemHTMLElement The element to toggle class name.
classNString The class name to toggle.
condBoolean <optional>
Boolean value to determine whether class name should be added or removed.