JS mouse click button to switch Pictures-Pictures automatically switch-click the left and right button switch special effects code _javascript tips

Source: Internet
Author: User

Today to share the mouse click button, the picture to switch + picture automatic switch + click on the left and right button picture to switch the combination of the three effects of the code.

The final effect is as follows:

HTML code section:

<!doctype html>  

CSS Code section:

 *{margin:0px;padding:0px} Li{list-style:none} A{text-decoration:none} img{border:0px }. banner{width:350px;height:495px;margin:100px Auto;position:relative;overflow:hidden}. Banner. pic{width:9999px; HEIGHT:495PX}. Banner. pic Li{width:350px;height:495px;float:left}. Banner. Anniu{width:100px;height:16px;position: absolute;left:165px;top:470px} banner. Anniu li{width:16px;height:16px;background:white;float:left;margin:2px;
Display:inline; cursor:pointer;border-radius:100%}. Banner. Anniu li.on{background:red} banner. lr{width:350px;height:50px; Position:absolute;top:250px;display:none}. Banner. LR a{color:white}. Banner. lr. Pre{width:20px;height:50px;float: Left;background:none repeat scroll 0px 0px rgba (1, 0, 0, 0.6); Text-align:center;line-height:50px;cursor:pointer}. Banner. LR. Next{width:20px;height:50px;float:right;background:none repeat scroll 0px 0px rgba (1, 0, 0, 0.6); Text-align: Center;line-height:50px;cursor:pointer} 

JavaScript code section:

$ (function () {//mouse over banner, left and right button to display and hide $ (". Banner"). Hover (function () {$ (. lr). Show ();
   },function () {$ (". LR"). Hide ();
   });
     Click on the small button below, the picture to toggle the effect of $ (". Anniu li"). Click (function () {$ (this). addclass (' on '). Siblings (). Removeclass ("on");
     var num=$ (this). index ();
   $ (". Pic"). Animate ({Marginleft:-350*num}, "slow");
   });
   Picture Automatic Carousel effect var a=0;
     var automatic=setinterval (function () {a++;
     a=a%5;
     $ (". Pic"). Animate ({marginleft:-350*a}, "slow");
   $ (". Anniu li"). EQ (a). addclass (' on '). Siblings (). Removeclass ("on");
   },6000);
     Click the left and right button, the picture to toggle the effect of $ (". Pre"). Click (function () {a--;
     A= (a+5)%5;
     $ (". Pic"). Animate ({marginleft:-350*a}, "slow");
   $ (". Anniu li"). EQ (a). addclass (' on '). Siblings (). Removeclass ("on");
   });
     $ (". Next"). Click (function () {a++;
     a=a%5;
     $ (". Pic"). Animate ({marginleft:-350*a}, "slow");
   $ (". Anniu li"). EQ (a). addclass (' on '). Siblings (). Removeclass ("on");
}); });

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.