CSS3 background image transition

前端 未结 13 2194
梦如初夏
梦如初夏 2020-11-22 07:07

I\'m trying to make a \"fade-in fade-out\" effect using the CSS transition. But I can\'t get this to work with the background image...

The CSS:



        
13条回答
  •  盖世英雄少女心
    2020-11-22 07:35

    With Chris's inspiring post here:

    https://css-tricks.com/different-transitions-for-hover-on-hover-off/

    I managed to come up with this:

    #banner
    {
        display:block;
        width:100%;
        background-repeat:no-repeat;
        background-position:center bottom;
        background-image:url(../images/image1.jpg);
        /* HOVER OFF */
        @include transition(background-image 0.5s ease-in-out); 
    
        &:hover
        {
            background-image:url(../images/image2.jpg);
            /* HOVER ON */
            @include transition(background-image 0.5s ease-in-out); 
        }
    }
    

提交回复
热议问题