5

这是我的 css sprite 代码的一部分

        #IconSet a {
        width: 36px;
        height: 36px;
        display: inline-block;
    }

    #DeviantArtIcon {
        border-width: 0px;
        border-style: none;
        background-image: url(http://static.monstermmorpg.com/images/csssprites/SocialIcons.png);
        background-color: transparent;
        background-repeat: repeat-x;
        background-position: -144px -0px;
        width: 36px;
        height: 36px;
    }

    #DeviantArtIcon:hover {
        border-width: 0px;
        border-style: none;
        background-image: url(http://static.monstermmorpg.com/images/csssprites/SocialIcons.png);
        background-color: transparent;
        background-repeat: repeat-x;
        background-position: -144px -36px;
        width: 36px;
        height: 36px;
    }

 <a id="DeviantArtIcon" href="http://monstermmorpg.deviantart.com" rel="nofollow" target="_blank" title="Monster MMORPG On Deviant Art - Please Watch Our Channel"></a>

现在,当这个图标悬停时,我想要有过渡效果。我怎样才能做到这一点 ?

我在这里试过但没有运气

悬停时背景图像之间的 CSS 淡入淡出

4

2 回答 2

10

将图像淡入另一个:

HTML:

<a id="deviant-art-icon" href="http://monstermmorpg.deviantart.com"><span></span></a>

CSS:

#deviant-art-icon {
    background:url(http://static.monstermmorpg.com/images/csssprites/SocialIcons.png) no-repeat;
    display: inline-block;
    position: relative;
    text-indent: -9999px;
    width: 36px;
    height: 36px;
    background-position: -144px -0px;
}

#deviant-art-icon span {
    position: absolute;
    top:0;
    left:0;
    bottom:0;
    right:0;  background:url(http://static.monstermmorpg.com/images/csssprites/SocialIcons.png) no-repeat;
    background-position: -144px -36px;
    opacity: 0;
    -webkit-transition: opacity 0.5s;
    -moz-transition:    opacity 0.5s;
    -o-transition:      opacity 0.5s;
}

#deviant-art-icon:hover span {
    opacity: 1;
}

演示:http: //jsfiddle.net/hxJyw/2/

于 2013-08-02T15:42:39.070 回答
1

1)您尚未transition effects在 CSS 中应用任何内容。

2)无需添加过渡:hover效果。

#DeviantArtIcon { 
-o-transition:2s ease-out, background 2s ease-in;
-ms-transition:2s ease-out, background 2s ease-in;
-moz-transition:2s ease-out, background 2s ease-in;
-webkit-transition:2s ease-out, background 2s ease-in;         
transition:2s ease-out, background 2s ease-in;
}

签入jSFiddle

希望这是你正在尝试的。

于 2013-08-02T15:33:52.553 回答