CSS3 Shutter Effect

Source: Internet
Author: User

Often when we look at some of the Web pages, we may see some cool special effects, such as the shutter effect. Most of the former is JS written out, but since CSS3 out, we can also use CSS code directly to achieve the shutter effect. Alas the ointment is IE9 below does not support our this very dazzling effect, then you can use JS to achieve compatibility. JS implementation Today we will not talk about, we talk about CSS3 it.

HTML structure is the key to making a pure CSS shutter effect. In the HTML structure, you need to use multiple images of the same image to organize a "shutter". In our demo, we make 4 shutters, need 4 identical <span>, and place them in a <div> tag. At the same time, we also need to set the four span background image as a complete picture. Each group of pictures is set to a different class. Then we'll use the backgroudn-potion: position.

First effect: Four span images are moved from the left to the right.

I had already put the HTML layout in place when I started to do it, and because I had to set a layer of positioning (but I didn't set it), the background images of 4 spans were all starting from the left. And then I added a label that sets each span to be positioned according to his parent element. (The next window bar should start with the top left corner where his parent element is positioned, which is the four red dots I drew below)

Second effect: four span picture rotation

Third effect: Is four span pictures made up of small size and then make up a perfect picture

Fourth effect: is set four span picture 3d rotation form a complete picture (here I am in trouble), because I set the animation name to 3d, and then I call when he always does not run. Can't you start with a number? I'm going to have to check it out for a while, so let's start with the alphabet when you set the animation name.


Code comparison rough (female man style)

HTML code:

<div class= "box" > <div class= "main" > <ul> <li> <!--&lt ; img src= "Images/1.jpg"/>--<div class= "Showbox showbox_1" > <div cl
                    ass= "Small Small_1" > <span></span> </div>
                    <div class= "Small small_2" > <span></span> </div>
                    <div class= "Small small_3" > <span></span>
                    </div> <div class= "Small small_4" > <span></span> </div> </div> </li> <li> & lt;!  ----<div class= "Showbox showbox_2" > <div class= "Small Small_1 "> <span></span> </div> <div clas
                    s= "Small small_2" > <span></span> </div>
                    <div class= "Small small_3" > <span></span> </div>
                    <div class= "Small small_4" > <span></span> </div> </div> </li> <li> <!----<div class= "Showbox showbox_3" > <div class= "Small Small_1 "> <span></span> </div> <d
                    IV class= "Small small_2" > <span></span> </div> <div class="Small small_3" > <span></span> </div>
               <div class= "Small small_4" > <span></span> </div> </div> </li> <li > <!-- <div class= "Small Small_1" > <span></span> </div> <div class= "small small_2 "> <span></span> </div> <div class
                    = "Small Small_3" > <span></span> </div>
               <div class= "Small small_4" > <span></span> </div> </div&Gt </li> </ul> </div> <div class= "nav" > <ul> <li class= "
        On "></li> <li></li> <li></li> <li></li> </ul> </div> </div>

CSS code:

*{margin:0; padding:0;}
ul,li{List-style:none;}
. box{width:604px; height:400px; border:1px solid red; margin:50px auto;position:relative; overflow:hidden;}
. main li{width:600px; height:400px;}
. inputradio{width:20px;height:20px; background:red; border-radius:50%;}
Label{font-style:italic;width:150px;height:30px;cursor:pointer;color: #fff; line-height:32px;font-size:24px; float:left;position:relative;margin-top:350px; z-index:1000; Background:blue;}
. nav{position:absolute;left:0; bottom:20px;width:100%; text-align:center; background:blue; z-index:100;}
. Nav li{width:20px; height:20px; float:left; margin-left:15px; border-radius:50%; background: #fff; border:3px solid #cc C POSITION:RELATIVE;BORDER:3PX solid #ccc;}
. Nav li.on{background: #fff000; border-color:pink;}
. Nav li:first-child{margin-left:35%;}
. showbox{width:100%; height:100%;p osition:absolute; left:0; top:0; z-index:80;}
. showbox > small{width:150px; height:100%; overflow:hidden; float:left;position:relative;
border-right:1px solid #fff;
-webkit-transition:left 2s ease-in-out;
-moz-transition:left 2s ease-in-out;
-o-transition:left 2s ease-in-out;
-ms-transition:left 2s ease-in-out;
Transition:left 2s ease-in-out;}
. small > span{display:block; width:100%; height:100%;overflow:hidden;position:absolute; left:0; top:0;}
. showbox_1. Small span{Background:url (images/1.jpg);}
. showbox_2. Small span{Background:url (images/2.jpg);}
. showbox_3. Small span{Background:url (images/3.jpg);}
. showbox_4. Small span{Background:url (images/4.jpg);}
. Showbox. Small:nth-child (1) span{background-position:0 0;}
. Showbox. Small:nth-child (2) span{background-position:-150px 0;}
. Showbox. Small:nth-child (3) span{background-position:-300px 0;}
. Showbox. Small:nth-child (4) span{background-position:-450px 0;}
. Small span{animation:lefts 1.2s ease;
-webkit-animation:lefts 1.2s Ease; }
. showbox_2 span{animation:rotate 1.2s ease;
-webkit-animation:rotate 1.2s Ease; }
. showbox_3 span{Animation:scale 1.2s ease-in forwards;/*forwards indicates that the last property value (as defined in the last keyframe) is maintained when the animation is complete */
-webkit-animation:scale 1.2s ease-in forwards; }
. showbox_4. small{
Transform:perspective (200px);
-webkit-transform:perspective (200px);

transform-style:preserve-3d;-webkit-transform-style:preserve-3d; /* If you set this property, the child elements that represent him are all running in 3d space */
}
. Showbox_4 span{
Animation:rotatey 1.2s ease-in-out;
-webkit-animation:rotatey 1.2s ease-in-out; }

/*left*/
@keyframes lefts{
0%{left:-150px;}
100%{left:0;}
}
@-webkit-keyframes lefts{
0%{left:-150px;}
100%{left:0;}
}
/*scale*/
@keyframes scale{
0%{transform:scale (0.2);}
100%{-webkit-transform:scale (1);}
}
@-webkit-keyframes scale{
0%{-webkit-transform:scale (0.2);
Transform:scale (0.2);}
100%{-webkit-transform:scale (1);
Transform:scale (1);}
}
/*rotate*/
@keyframes rotate{
0%{transform:rotate (0deg);}
100%{transform:rotate (360deg);}
}
}
@-webkit-keyframes rotate{
0%{-webkit-transform:rotate (0deg);}
100%{-webkit-transform:rotate (360deg);}
}
/*rotatey*/
@keyframes rotatey{
0%{transform:rotatey (0deg) Rotatex (0deg);}
100%{transform:rotatey (360deg) Rotatex (30deg);}
}
@-webkit-keyframes rotatey{
0%{-webkit-transform:rotatey (0deg) Rotatex (0deg);}
100%{-webkit-transform:rotatey (360deg) Rotatex (30deg);}
}

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.