
на русском v1.2.5 Документацитя по MooTools 1.4.5 Обсуждение Установить себе Благодарности
Attaches an event listener to a DOM element.
myElement.addEvent(type, fn);
<div id="myElement">Click me.</div>
$('myElement').addEvent('click', function(){ alert('clicked!'); });
Works as Element.addEvent, but instead removes the specified event listener.
myElement.removeEvent(type, fn);
var destroy = function(){ alert('Boom: ' + this.id); } // this refers to the Element. $('myElement').addEvent('click', destroy); // later $('myElement').removeEvent('click', destroy);
var destroy = function(){ alert('Boom: ' + this.id); } var boundDestroy = destroy.bind($('anotherElement')); $('myElement').addEvent('click', boundDestroy); // later $('myElement').removeEvent('click', destroy); // this won't remove the event. $('myElement').removeEvent('click', destroy.bind($('anotherElement')); // this won't remove the event either. $('myElement').removeEvent('click', boundDestroy); // this is the correct way to remove the event.
The same as Element:addEvent, but accepts an object to add multiple events at once.
myElement.addEvents(events);
$('myElement').addEvents({ 'mouseover': function(){ alert('mouseover'); }, 'click': function(){ alert('click'); } });
Removes all events of a certain type from an Element. If no argument is passed, removes all events of all types.
myElements.removeEvents([events]);
var myElement = $('myElement'); myElement.addEvents({ 'mouseover': function(){ alert('mouseover'); }, 'click': function(){ alert('click'); } }); myElement.addEvent('click', function(){ alert('clicked again'); }); myElement.addEvent('click', function(){ alert('clicked and again :('); }); //addEvent will keep appending each function. //Unfortunately for the visitor, that'll be three alerts they'll have to click on. myElement.removeEvents('click'); // This saves the visitor's finger by removing every click event.
Executes all events of the specified type present in the Element.
myElement.fireEvent(type[, args[, delay]]);
// Fires all the added 'click' events and passes the Element 'anElement' after one second. $('myElement').fireEvent('click', $('anElement'), 1000);
Clones all events from an Element to this Element.
myElement.cloneEvents(from[, type]);
var myElement = $('myElement'); var myClone = myElement.clone().cloneEvents(myElement); //clones the element and its events
You can add additional custom events by adding properties (objects) to the Element.Events Hash
The Element.Events.yourproperty (object) can have:
Element.Events.shiftclick = { base: 'click', //we set a base type condition: function(event){ //and a function to perform additional checks. return (event.shift == true); //this means the event is free to fire } }; $('myInput').addEvent('shiftclick', function(event){ log('the user clicked the left mouse button while holding the shift key'); });
There are different types of custom Events you can create:
If you use the condition option you NEED to specify a base type, unless you plan to overwrite a native event. (highly unrecommended: use only when you know exactly what you're doing).
This event fires when the mouse enters the area of the DOM Element and will not be fired again if the mouse crosses over children of the Element (unlike mouseover).
$('myElement').addEvent('mouseenter', myFunction);
This event fires when the mouse leaves the area of the DOM Element and will not be fired if the mouse crosses over children of the Element (unlike mouseout).
$('myElement').addEvent('mouseleave', myFunction);
This event fires when the mouse wheel is rotated;
$('myElement').addEvent('mousewheel', myFunction);
© Linux.ria.ua, 2008-2018 |