代碼,終于拿到了
<!DOCTYPE html>
<html>
<head>
?? ?<title>css+js預(yù)覽圖幻燈片</title>
?? ?<meta charset="utf-8">
?? ?<style type="text/css">
?? ?*{padding:0; margin: 0;}
?? ?body{
?? ??? ?padding:50px 0;/*上下邊距*/
?? ??? ?background-color: #FFF;
?? ??? ?font-size:14px;
?? ??? ?font-family:'Avenir14px;
?? ??? ?color:#555; Next';
?? ??? ?-webkit-font-smooting:antialiased;
?? ??? ?-o-font-smooting:antialiased;
??????? -moz-font-smoooting:antialiased;
??????? -ms-font-smooting:antialiased;/*字體抗鋸齒
?? ??? ?*/
?? ?}
?? ?.slider,
?? ?.slider .main,
?? ?.slider .main .main-i{
?? ??? ?width: 100%;
?? ??? ?height: 400px;
?? ??? ?position: relative;
?? ?}
?? ?/*幻燈片區(qū)域*/
?? ?.slider .main{
?? ??? ?overflow: hidden;
?? ?}
?? ?/*每一個(gè)幻燈片的樣式*/
?? ?.slider .main .main-i{}
?? ?.slider .main .main-i img{
?? ??? ?width: 100%;
?? ??? ?position: absolute;/*飄浮*/
?? ??? ?left: 0;
?? ??? ?top: 50%;
?? ??? ?z-index:1;
?? ?}
?? ?.slider .main .main-i .caption{
?? ??? ?position: absolute;
?? ??? ?right: 50%;
?? ??? ?top: 30%;
?? ??? ?z-index: 9;
?? ?}
?? ?.slider .main .main-i .caption h2{
?? ??? ?font-size: 40px;
?? ??? ?line-height: 50px;
?? ??? ?color: #B5B5B5;
?? ??? ?text-align: right;
?? ?}
?? ?.slider .main .main-i .caption h3{
?? ??? ?font-size: 70px;
?? ??? ?line-height: 70px;
?? ??? ?color: #000000;
?? ??? ?text-align: right;
?? ??? ?font-family: 'Open Sans Condensed';
?? ?}
?? ?/*控制按鈕區(qū)域*/
?? ?.slider .ctrl{
?? ??? ?width: 100%;
?? ??? ?height: 13px;
?? ??? ?line-height: 13px;
?? ??? ?text-align: center;
?? ??? ?position: absolute;
?? ??? ?left: 0;
?? ??? ?bottom: -13px;
?? ??? ?/*background-color: #f00;*/
?? ?}
?? ?.slider .ctrl .ctrl-i{
?? ??? ?display: inline-block;/*定義了該屬性,后面設(shè)置寬和高才會(huì)起作用*/
?? ??? ?width: 150px;
?? ??? ?height: 13px;
??????? background-color: #666;
??????? box-shadow: 0 1px 1px rgba(0,0,0,.3);
??????? position: relative;
??????? margin-left: 1px;
?? ?}
?? ?.slider .ctrl .ctrl-i img{
?? ??? ?width: 100%;
?? ??? ?position: absolute;
?? ??? ?left: 0;
?? ??? ?bottom: 50px;
?? ??? ?z-index: 1;
?? ??? ?opacity: 0;
?? ??? ?-webkit-transition:all .2s;
?? ??? ?-o-transition:all 0.2s;
?? ??? ?-moz-transition:all 0.2s;
?? ??? ?transition:all 0.2s;
?? ??? ?
?? ?}
?? ?/*hover 到控制按鈕的樣式*/
?? ?.slider .ctrl .ctrl-i:hover{
?? ??? ?background-color: #f0f0f0;
?? ?}
?? ?.slider .ctrl .ctrl-i:hover img{
?? ??? ?bottom:13px;
?? ??? ?-webkit-box-reflect:below 0px -webkit-gradient(
?? ??? ??? ?? linear,
?? ??? ??? ?? left top,
?? ??? ??? ?? left bottom,
?? ??? ??? ?? from( transparent),
?? ??? ??? ?? color-stop(50%, transparent),
?? ??? ??? ?? to(rgba(255,255,255,.3))
?? ??? ??? ?) ;
?? ??? ?-o-box-reflect:below 0px -webkit-gradient(
?? ??? ??? ?? linear,
?? ??? ??? ?? left top,
?? ??? ??? ?? left bottom,
?? ??? ??? ?? from( transparent),
?? ??? ??? ?? color-stop(50%, transparent),
?? ??? ??? ?? to(rgba(255,255,255,.3))
?? ??? ??? ?) ;
??????? -moz-box-reflect:below 0px -webkit-gradient(
?? ??? ??? ?? linear,
?? ??? ??? ?? left top,
?? ??? ??? ?? left bottom,
?? ??? ??? ?? from( transparent),
?? ??? ??? ?? color-stop(50%, transparent),
?? ??? ??? ?? to(rgba(255,255,255,.3))
?? ??? ??? ?) ;
??????? -ms-box-reflect:below 0px -webkit-gradient(
?? ??? ??? ?? linear,
?? ??? ??? ?? left top,
?? ??? ??? ?? left bottom,
?? ??? ??? ?? from( transparent),
?? ??? ??? ?? color-stop(50%, transparent),
?? ??? ??? ?? to(rgba(255,255,255,.3))
?? ??? ??? ?) ;
?? ??? ?box-reflect:below 0px -webkit-gradient(
?? ??? ??? ?? linear,
?? ??? ??? ?? left top,
?? ??? ??? ?? left bottom,
?? ??? ??? ?? from( transparent),
?? ??? ??? ?? color-stop(50%, transparent),
?? ??? ??? ?? to(rgba(255,255,255,.3))
?? ??? ??? ?) ;
?? ??? ?opacity: 1;
?? ??? ?z-index: 20;
?? ?}
?? ?/*active 當(dāng)前展現(xiàn)的狀態(tài)*/
?? ?.slider .ctrl .ctrl-i_active:hover,
?? ?.slider .ctrl .ctrl-i_active{
?? ??? ?background-color: #000;
?? ?}
?? ?.slider .ctrl .ctrl-i_active:hover img{
?? ??? ?opacity: 0;
?? ?}
?? ?/*幻燈片切換樣式*/
?? ?.slider .main .main-i{
?? ??? ?opacity: 0;
?? ??? ?position: absolute;
?? ??? ?right: 50%;
?? ??? ?top: 0;
?? ??? ?-webkit-transition:all .5s;
?? ??? ?transition:all 0.5s;
??????? -o-transition:all 0.5s;
??????? -moz-transition:all 0.5s;
?? ?}
?? ?.slider .main .main-i h2{
???????? margin-right: 45px;
?? ?}
?? ?.slider .main .main-i h3{
?? ??? ?margin-right: -45px;
?? ?}
?? ?.slider .main .main-i h2,
?? ?.slider .main .main-i h3{
?? ??? ?-webkit-transition:all .8s 1s;
?? ??? ?transition:all 1s 0.8s;
??????? -o-transition:all 1s 0.8s;
??????? -moz-transition:all 1s 0.8s;
?? ?}
?? ?
??? #main_background,
??? .slider .main .main-i_active{
??????????????? right:0;
??????????????? opacity:1;
??????????????? z-index:2;
??????????? }
?????????? ?
?? #main_background{
??????????????? z-index:1;
??????????? }
?? ?.slider .main .main-i_active h2,
?? ?.slider .main .main-i_active h3{
?? ??? ?margin-right: 0px;
?? ??? ?opacity: 1;
?? ?}
?? ?.slider .main .main-i .caption{
?? ??? ?margin-right: 13%;
?? ?}
?? ?</style>
</head>
<body>
<div class="slider">
??????????? <div class="main" id="template_main">
??????????????? <div class="main-i {{css}}" id="main_{{index}}">
??????????????????? <div class="caption">
??????????????????????? <h2>{{h2}}</h2>
??????????????????????? <h3>{{h3}}</h3>
??????????????????? </div>
??????????????????? <img src="./img/{{index}}.png" class="picture"/>
??????????????? </div>
??????????? </div>
?????????? ?
??????????? <!--控制區(qū)域-->
??????????? <div class="ctrl" id="template_ctrl">
??????????????? <a class="ctrl-i" id="ctrl_{{index}}" href="javascript:switchSlider({{index}});">
??????????????????? <img src="./img/{{index}}.png"/>
??????????????? </a>
??????????? </div>
??????????? <!--VCD:js就是C=controller-->
2015-12-23
//6.動(dòng)態(tài)調(diào)整圖片的margin-top以使其垂直居中
function movePictures(){
var pictures = g('.picture');
for(i=0;i<pictures.length;i++){
pictures[i].style.marginTop = (-1 * pictures[i].clientHeight/2 ) + 'px'
}
}
//4.定義何時(shí)處理幻燈片輸出
window.onload = function(){
addSliders();
switchSlider(2);
setTimeout(function(){
movePictures()
},100)
}
這是我寫的,實(shí)現(xiàn)了,你可以試一試
2015-09-18
這是我的CSS源碼:
2015-09-18
我來把腳本這塊補(bǔ)充完整:
當(dāng)然,后面的垂直居中、不顯示白底還有隨機(jī)切換效果那塊我沒能實(shí)現(xiàn),搞了半天就是不知道問題出現(xiàn)在哪里!