京東圖片遍歷
阿新 • • 發佈:2018-04-12
alt 技術分享 spl absolut cor set AD ++ image
HTML部分:
<div id="lifeservice" class="serve">
<ul>
<li>
<a href="#" style="color: red">
<i></i>
<span>話費</span>
</a>
</li>
<li>
<a href="">
<i></i>
<span>機票</span>
</a>
</li>
<li>
<a href="">
<i></i>
<span>電影票</span>
</a>
</li>
<li>
<a href="">
<i></i>
<span>遊戲</span>
</a>
</li>
<li>
<i></i>
<a href="">
<span>彩票</span>
</a>
</li>
<li>
<i></i>
<a href="">
<span>團購</span>
</a>
</li>
<li>
<i></i>
<a href="">
<span>酒店</span>
</a>
</li>
<li>
<i></i>
<a href="">
<span>水電煤</span>
</a>
</li>
<li>
<i></i>
<a href="">
<span>眾籌</span>
</a>
</li>
<li>
<i></i>
<a href="">
<span>理財</span>
</a>
</li>
<li>
<i></i>
<a href="">
<span>禮品卡</span>
</a>
</li>
<li>
<a href="">
<i></i>
<span>白條</span>
</a>
</li>
</ul>
CSS部分:
@charset "UTF-8";
.serve {
height: 251px;
/**/
height:251px ;
overflow: hidden;
}
.serve ul{
width:252px ;
}
.serve ul li{
width: 62px;
height: 70px;
border-top: 1px solid black;
float:left;
margin-left: -1px;
border-top: 0;
list-style: none;
position: relative;
}
.serve ul li a{
display: block;
height: 70px;
text-align: center;
padding-top: 46px;
text-decoration: none;
}
.serve ul li i{
top:12px;
left:18px;
width: 25px;
height: 25px;
background: url(images/1.png) no-repeat right top ;
position: absolute;
}
JS部分:
<script>
var Life=document.getElementById("lifeservice").getElementsByTagName("i");
for(var i=1;i<=Life.length;i++){
Life[i].style.backgroundPosition="0 "+(-25*i)+"px";
}
</script>
京東圖片遍歷