background-size with background-position doesn't scale the position?

前端 未结 6 1724
轮回少年
轮回少年 2021-02-05 13:16

I\'ve a sprite of 62 images of 91 * 91px, which makes the whole thing 91 * 5642 px. They\'re displayed in sort of a dynamic grid that grows and shrinks depending on user/pointer

6条回答
  •  轮回少年
    2021-02-05 13:49

    If your requirement is smoother transition than this is what you need.

    DEMO

    DEMO2 with centered zoom.

    HTML:

     Hover image large transition
    Hover that:

    CSS:

     p {
        margin: 0;
        display: inline-block;
        
    }
    a {
        display: block;
        border: solid 10px green;
        /* always: */
        width: 91px;
        height: 91px;
        background: black url(//hotblocks.nl/tests/gamessprite.gif) no-repeat 0 0;
        background-size: 100% auto;
    
        /* inline: */
        background-position: 0 -182px;
         -webkit-transition: all .5s;
        -moz-transition: all .5s;
        -o-transition: all .5s;
        transition: all .5s;
    }
    a:hover {
        -webkit-transform: scale(1.3);
        -ms-transform: scale(1.3);
        transform: scale(1.3);
        -webkit-transform-origin: 0 0;
        -ms-transform-origin: 0 0;
        transform-origin: 0 0;
        -webkit-transition: all .5s;
        -moz-transition: all .5s;
        -o-transition: all .5s;
        transition: all .5s;
    }
    

    Fiddle: fiddle

提交回复
热议问题