使用css3精灵进行过渡

时间:2012-12-24 08:14:13

标签: html css3 css-sprites

我想使用css3淡入和淡出图像(精灵)。下面的代码给出了所有图像的过渡。帮助我淡入并淡出css精灵中的下面图像。

HTML CODE

 <div class="navigation">
    <div class="navigation1 process-normal" id="process"></div>
  <div class="navigation1 works-normal" id="works"></div>
  <div class="navigation1 team-normal" id="team"></div>
  <div class="navigation1 products-normal" id="products"></div>
  <div class="navigation1 services-normal" id="services"></div>

CSS

.services-active, .products-active, .works-active,
.process-normal, .process-active, .products-normal, .team-normal, .team-active, 
.works-normal,.brain,.static,.services,.people,.servies-normal
 { display: block; background: url('allimages.png') no-repeat; }
.navigation1
{
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}

1 个答案:

答案 0 :(得分:0)

检查此site,了解如何使用图像精灵实现CSS过渡。

DEMO(从上面的链接分叉)

<强> HTML

<a href="#" class="arrow">Arrow<span></span></a>

<强> CSS

.arrow {
    display: inline-block;
    position: relative;
    text-indent: -9999px;
    width: 36px;
    height: 36px;
    background: url(sprites.png) no-repeat;
}

.arrow span {
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: url(sprites.png) no-repeat;
    background-position: -50px 0;
    opacity: 0;
    -webkit-transition: opacity 0.5s;
    -moz-transition:    opacity 0.5s;
    -o-transition:      opacity 0.5s;
}

.arrow:active span {
    opacity: 1;
}