CSS3 implementation of Carousel switching effect

Source: Internet
Author: User

The general idea of implementing the carousel is to switch the infinite elements in a large box, the large box fixed size, outside the box range to hide, and the infinite elements can be any stacking, according to a certain step of the position transformation, has reached the visual area to show the effect we want.

See an example:

HTML code:

1 <Divclass= "Trans_box">2 <DivID= "Transimagebox"class= "Trans_image_box">3     <Divclass= "Trans_image"style= "Width:300px;height:200px;background:blue;">111</Div>4     <Divclass= "Trans_image"style= "width:300px;height:200px;background:red;">222</Div>5     <Divclass= "Trans_image"style= "Width:300px;height:200px;background:orange;">333</Div>6 </Div>7 <DivID= "Transimagetrigger"class= "Trans_image_trigger">8     <ahref= "#1">Picture 1</a>   <ahref= "#2">Picture 2</a>   <ahref= "#3">Picture 3</a>9 </Div>Ten </Div>

CSS code:

1 . Trans_box{2 width:300px;3 Overflow:Hidden;4}5 . Trans_image_box{6 width:20000px;7 Height:200px;8 -webkit-transition:All 1s ease-in-out;9 -moz-transition:All 1s ease-in-out;Ten -o-transition:All 1s ease-in-out; One transition:All 1s ease-in-out; A} - . Trans_image_box. Trans_image{ - float: Left; the width:200px; -} - . Trans_image_trigger{ - Padding-top:10px; + text-align:Center; -}

JS Code:

1 var$ =function(ID) {2     returndocument.getElementById (ID);3 };4 var$box = $ ("Transimagebox"),5$oTrigger = $ ("Transimagetrigger"). getElementsByTagName ("a"),6$len =$oTrigger. Length;7  for(vari = 0; i < $len; i++) {8$oTrigger [I].onclick =function(){9             varindex = number ( This. Href.replace (/.*#/g, ")) | | 1;Ten$box. Style.marginleft = (1-index) * + "px"; One             return false; A       }; -}

Click to view demo effect

CSS3 implementation of Carousel switching effect

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.