Two very interesting jquery switching methods-hover-Toggle

Source: Internet
Author: User
Hover:

Hover is a custom method that describes status 1 and status 2. It is triggered by sliding the mouse. The effect is similar to that of onmousemove onmouseout. This state is described in a small example. In fact, hover is widely used in complex animation rich web applications. Among the function () {}, function () {} callback functions, we can use a wide range of extensions.

. Hover (function () {...}, function (){..});

 <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >  <  Html  Xmlns  = "Http://www.w3.org/1999/xhtml"   >  <  Head >      <  Title  > Untitled page </  Title  >      <  Style  Type  = "Text/CSS"  >  # De  {}      </  Style >      <  Script  Type  = "Text/JavaScript"  SRC  = "Jquery-1.6.4.min.js"  > </  Script  >      <  Script  Type  = "Text/JavaScript"  >  $ ( Function  (){  VaR  $ De  =  $ (  "  # De  "  ); $ De. Hover (  Function () {$ (  This  ).Css (  "  Background  "  ,  "  # Ccc  "  );},  Function () {$ (  This  ).Css (  "  Background  "  ,  "  #999  "  );});});  </ Script  >  </  Head  >  <  Body  >      <  A  Href  = "#"  ID  = "De"  > Content </  A >  </  Body  >  </  Html  > 
Toggle:

In jquery, toggle is a fun idea. It is used to bind multiple event processor functions to respond to the rotating click events of the selected elements. If the element is visible, switch to hidden. If the element is hidden, switch to visible.

. Toggle (function () {}, function (){},....);. toggle (speed, function (){});. toggle (speed, easing, function (){});

Speed: Display and hide speed. The default value is 0.

Easing: Specifies the switching effect. The default value is swing, and the optional value is linear.

The. Toggle () method also has a Switch Parameter format. For example, I set a parameter to int, $ ("..."). Toggle (INT ). It has the following similar effects:

Int? $ (".."). Show (): $ (".."). Hide ();

 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >  <  Html  Xmlns  = "Http://www.w3.org/1999/xhtml"   >  <  Head  >      <  Title  > Untitled page </  Title >      <  Style  Type  = "Text/CSS"  >  # De  {}  . De  {  Background  :  # Ccc ;  Width  :  50px  ;  Height  :  50px  ;  Margin-top  :  50px ;  Display  :  None  ;  }      </  Style  >      <  Script  Type  = "Text/JavaScript"  SRC = "Jquery-1.6.4.min.js"  > </  Script  >      <  Script  Type  = "Text/JavaScript"  >  $ (  Function  (){  VaR  $ De =  $ (  "  # De  "  ); $ De. Toggle (  Function  () {$ (  "  . De  "  ). Fadein ( "  Slow  "  );},  Function  () {$ (  "  . De  "  ). Fadeout (  "  Slow "  );});});  </  Script  >  </  Head  >  <  Body  >      <  A  Href  = "#"  ID = "De"  > Content </  A  >      <  Div  Class  = "De"  > </  Div  >  </  Body  >  </  Html >
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.