Toggle an Action
The toggleAction()
is a SniperJs method that alternates between two given functions of actions.
This method takes up to callbacks, your initial Action
and the reverse Action
toggleAction(initialAction, reverseAction);
This is an example of the toggleAction
method switches between two actions for all the elements with the .cont
class inside a .wrapper
. One action expands the element to show its full <p>
content, while the other shrinks it back to 18 pixels height.
$('.wrapper .cont*').toggleAction(function(e){
this.height(this.find('p').height() + 18);
},
function(e) {
this.height(18);
);
NOTE:
The 'this' keyword refers to the selected element.
The 'this' keyword can only refer to the selected element if the
function
keyword is used.The 'this' keyword
does not
work witharrow functions
Last updated