Javascript preload images for css background-image change

前端 未结 4 1169
猫巷女王i
猫巷女王i 2021-01-15 06:16

I am developing a website which requires the background image of a div to change on hover of a link.

The way it works is by:



        
4条回答
  •  逝去的感伤
    2021-01-15 06:55

    Stack your images as one image, and then add a class that shifts the image's background property to the appropriate offset.

    Not only does this turn multiple images into one HTTP request, it also means you don't have to bother writing code to preload the hover state of the images.

    This is called a sprite sheet.

提交回复
热议问题