Prevent background image flashing on change

后端 未结 2 408
难免孤独
难免孤独 2021-01-27 17:19

I\'m using background image for a button and switch to a different one on :hover.

When the switch happens on the first mouse over it briefly flashes the bac

2条回答
  •  故里飘歌
    2021-01-27 18:02

    Load both images using multiple background and make the first one on the top then adjust background-size to show the other on hover. In this case, both images will be loaded initially and the second one will be ready on hover:

    .backgroundbutton {
      background-image: 
       url('http://www.BungalowSoftware.com/images/silver-background.jpg'),
       url('http://www.BungalowSoftware.com/images/silver-background2.jpg');
      background-size:auto;
      width: 100px;
      height: 30px;
      background-color: orange;
    }
    
    .backgroundbutton:hover {
      background-size:0 0,auto;
    }
      hover over me

提交回复
热议问题