jquery39 classic case ------ sidebar ad

1. First, recognize that toggle (),

Definition and Usage

Toggle () method is used to bind two or more event handler function in response to rotation of the click event selected element.

The method can also be used to switch the selected element  hide ()  and  show ()  method.

Examples

Switching different background colors:

$("p").toggle(
  function(){
  $("body").css("background-color","green");},
  function(){
  $("body").css("background-color","red");},
  function(){
  $("body").css("background-color","yellow");}
);

Bind two or more functions to the Toggle events

When the specified element is clicked, alternately switching between two or more functions .

If more than two predetermined functions, the Toggle () method switches all functions. For example, if there are three functions, the first click will call the first function, the second click to call the second function, the third click to call the third function. Fourth click calls the first function again, and so on.

grammar

$(selector).toggle(function1(),function2(),functionN(),...)

Switching Hide () and Show ()

Check each element is visible .

If the element is hidden, then run the show (). If the element is visible, then the element hide (). So that you can create transitions .

grammar

$(selector).toggle(speed,callback)

Show or hide elements

Provisions only if all the elements to show or hide only match.

grammar

$ ( Selector ) .toggle ( Switch ) 
Switch --- parameter is "true to display this element
represents this element is false to hide

instances ===================== ==========================================

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/hou-yuan-zhen/p/11608004.html