Adds a semi-transparent overlay over a DOM element.
Implements
See Also
Syntax
new Mask(target[, options]);
Arguments
- target - (mixed) A string of the id for an Element or an Element reference to overlay; defaults to document.body
- options - (object) a key/value set of options
Options
- inject - (object) where to inject the layer. If not specified, the mask is injected into the document body. Example: inject: { where: 'after', target: element }
- hideOnClick - (boolean) if true, the mask will hide when clicked. Defaults to false.
- id - (string) if defined, the overlay layer will be assigned this id. If not defined, the id will default to 'mask-
' - destroyOnHide - (boolean) if true the mask layer is destroyed when hidden. The class will no longer function after this. Defaults to false.
- class - (string) the css class to apply to the layer; defaults to 'mask'.
- style - (object) if defined, will apply to the mask with Element.setStyles. You can also style the layer by just defining a style for the layer class name (defaults to ".mask"). Default styles can be found in the Styles directory of the MooTools More library on github or downloaded on the More builder on MooTools.net.
- maskMargins - (boolean) if true the mask will extend to the margins of the target. Defaults to false.
- useIframeShim - (boolean) if true the mask will use IframeShim to hide OS elements (select boxes, flash, etc) for IE6.
- iframeShimOptions - (object) options passed to IframeShim.
Events
- show - (function) callback to execute when the layer is shown; passed the target element to which the Mask was attached.
- hide - (function) callback to execute when the layer is hidden; passed the target element to which the Mask was attached.
- destroy - (function) callback to execute when the layer is destroyed.
- click - (function) callback to execute when the layer is clicked.
Examples
var myMask = new Mask();
var myMask = new Mask($('myElement'));
Styles
The mask element is not styled, so if you don't add a css rule in your style sheets, it will be invisible. You can download the default styles here: mask.css
Toggles the Mask visibility. If the Mask is currently visible, it will hide. Otherwise it will display.
Syntax
myMask.toggle(element);
Arguments
- element - (mixed, optional) A string of the id for an Element or an Element reference to overlay; defaults to the target passed in at initialization, but you can specify a different element if you wish to reuse the class.
Returns
- (object) This instance of Mask
Displays the Mask layer.
Syntax
myMask.show();
Returns
- (object) This instance of Mask
Hides the Mask layer.
Syntax
myMask.hide();
Returns
- (object) This instance of Mask
Destroys the Mask layer. This renders the instance of this class inert (and further calls to its methods will throw errors).
Syntax
myMask.destroy()
Returns
- (object) This instance of Mask
Reasserts the position of the overlay layer.
Syntax
myMask.position()
Returns
- (object) This instance of Mask
Reasserts the dimensions of the overlay layer. Note that this method is called when Mask.position is called, so you needn't call it if you call position.
Syntax
myMask.resize()
Returns
- (object) This instance of Mask
Extends the Element Type with Mask methods.
Setter
Sets a default Mask instance for an Element.
Syntax
el.set('mask'[, options]);
Arguments
- options - (object, optional) The Mask options.
Returns
- (element) This Element.
Examples
el.set('mask', {onClick: function(){..etc..}});
el.mask(); //obscure the element with the overlay
el.unmask(); //hide the overlay
Getter
Gets the default Mask instance for the Element.
Syntax
el.get('mask');
Arguments
- name - (string) This should always be 'mask'.
Returns
- (object) The Element's internal Mask instance.
Examples
el.set('mask', {onClick: function(){..etc..}});
el.mask(); //show the mask
el.get('mask'); //The Mask instance.
Adds Mask shortcuts to the Element class.
Retrieves the "build-in" instance of Mask and calls its show method.
Syntax
$('myElement').mask([options]);
Arguments
- options - (object - optional) the options for the default mask.
Returns
- (element) This Element
Retrieves the "build-in" instance of Mask and calls its hide method.
Syntax
$('myElement').unmask();
Returns
- (element) This Element