Javascript combined with CSS to implement special effects on Apple's switch button _ javascript skills

Source: Internet
Author: User
This article mainly introduces how to use javascript and CSS to implement special effects of Apple switch buttons and all the code. The results are very good and the compatibility is also good. If you need them, refer to the effect of Apple switch buttons ~~

When disabled

Html

The Code is as follows:






Apple button







Css

The Code is as follows:


# P1 {
Width: 170px;
Height: 100px;
Border-radius: 50px;
Position: relative;
}
# P2 {
Width: 96px;
Height: 96px;
Border-radius: 48px;
Position: absolute;
Background: white;
Box-shadow: 0px 2px 4px rgba (0, 0, 0, 0.4 );
}
. Open1 {
Background: rgba (0,184, 0, 0.8 );
}
. Open2 {
Top: 2px;
Right: 1px;
}
. Close1 {
Background: rgba (255,255,255, 0.4 );
Border: 3px solid rgba (0, 0, 0, 0.15 );
Border-left: transparent;
}
. Close2 {
Left: 0px;
Top: 0px;
Border: 2px solid rgba (0.1, 0 );
}

Javascript

The Code is as follows:


Window. onload = function (){
Var p2 = document. getElementById ("p2 ");
Var p1 = document. getElementById ("p1 ");
P2.onclick = function (){
P1.className = (p1.className = "close1 ")? "Open1": "close1 ";
P2.className = (p2.className = "close2 ")? "Open2": "close2 ";
}
}

The above is all the content of this article, hoping to help you master the WEB Front-end design.

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.