为什么只有标题会出现而图标不会出现了呢?
这是我的代码:
@charset "utf-8";
*{
margin:0;
border:0;
padding:0;
}
body{
padding:50px 0;
background-color:#fff;
font-size:14px;
font-family:Arial, Helvetica, sans-serif;
color:#555;
-webkit-font-smoothing:antialiased;/*字体抗锯齿*/
display:-webkit-box;/*使用流动盒子元素时适应chrome*/
display:-moz-box;/*适应fire-fox*/
display:box;/*适应其他浏览器除ie*/
}
.slider{
width:100%;
height:400px;
position:relative;
}
/*幻灯片区域*/
.slider .main{
width:100%;
height:400px;
position:relative;
overflow:hidden;
}
/*每一个幻灯片的样式*/
.slider .main .main-i{
width:100%;
height:400px;
position:relative;
}
.slider .main .main-i img{
width:100%;
position:absolute;
top:0;
left:0;
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:000;
text-align:right;
}
/*控制按钮槽样式*/
.slider .ctrl{
width:100%;
height:13px;
line-height:13px;
text-align:center;
position:absolute;
left:0;
bottom:-13px;
background-color:#333;
}
/*控制按钮*/
.slider .ctrl .ctrl-i{
display:inline-block;/*使每一个块状元素同行显示*/
width:150px;
height:13px;
background-color:#666;
text-shadow:0 1px 1px rgb(0,0,0,.3);
position:relative;/*子元素img是绝对定位所以父元素定义为相对定位*/
margin-left:1px;
}
.slider .ctrl .ctrl-i img{
width:100%;
left:0;
bottom:50px;
position:absolute;
z-index:1;
opacity:0;/*将图片透明隐藏*/
-webkit-transition:all .2s;/*图片出现动画延迟2秒*/
}
/*当鼠标移到控制按钮的时候变成一个浅灰色*/
.slider .ctrl .ctrl-i:hover{
background-color:#f0f0f0;
}
/*当鼠标移到控制按钮的时候图像的变动*/
.slider .ctrl .ctrl-i:hover img{
bottom:13px;
opacity:1;/*将图片显示*/
}
/*active当前展示状态*/
.slider .ctrl .ctrl-i_active:hover,.slider .ctrl .ctrl-i_active{
background-color:#666;
}
.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;
}
.slider .main .main-i_active{
right:0;
opacity:1;
}
.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;
}
.slider .main .main-i_active h2,.slider .main .main-i_active h3{
margin-right:0px;
}
js 的
//1.数据定义(实际环境应有后台给出)
var data = [
{img:1,h1:'lllllla',h2:'1113212'},
{img:2,h1:'lllllls',h2:'111321212'},
{img:3,h1:'lllllld',h2:'111212'},
{img:4,h1:'llllllf',h2:'1113212'},
{img:5,h1:'llllllx',h2:'11131212'},
{img:6,h1:'lllllls',h2:'11112'},
{img:7,h1:'lllllla',h2:'1113212'}
];
//2.定义通用函数
var g = function (id){
if(id.substr(0,1) == '.'){
return document.getElementsByClassName(id.substr(1));
}
return document.getElementById(id);
}
//3.添加幻灯片操作(所有幻灯片和按钮)
function addSliders(){
//3.1 获取模板
var tpl_main = g('template_main').innerHTML
.replace(/^\s*/,'')
.replace(/\s*$/,'');
var tpl_ctrl = g('template_ctrl').innerHTML //控制按钮的模板
.replace(/^\s*/,'')
.replace(/\s*$/,'');
//3.2定义最终输出HTML 的变量
var out_main = [];//输出所有幻灯片
var out_ctrl = [];//输出所有控制按钮
//3.3 遍历所有数据,构建最终输出的HTML
for(var i = 0;i < data.length;i++)
{
var _html_main = tpl_main.replace(/{{index}}/g,data[i].img).replace(/{{h2}}/g,data[i].h1).replace(/{{h3}}/g,data[i].h2);
//替换临时变量,g表示全局替换
var _html_ctrl = tpl_ctrl.replace(/{{index}}/g,data[i].img);
out_main.push(_html_main);
out_ctrl.push(_html_ctrl);
}
//3.4 把HTML回写到对应的DOM 里面
g('template_main').innerHTML = out_main.join('');//所有幻灯片
g('template_ctrl').innerHTML = out_ctrl.join('');//所有控制按钮
}
//4.定义何时出理 当窗口打开的时候再添加灯片
window.onload = function(){
addSliders();
//switchSlider(1);
}