Does hiding an animated GIF with CSS conserve browser resources?

前端 未结 4 1294
庸人自扰
庸人自扰 2021-02-20 10:10

I have a gif image. It gets shown only on very specific events, not too often. By default, the gif\'s html tag is hidden using display: none

4条回答
  •  情歌与酒
    2021-02-20 11:05

    It shouldn't. In the MDN document for none value on display, It said that

    The document is rendered as though the element did not exist.

    A Timeline test on chrome:

    Image used: https://imgur.com/download/i8kbwLN ( 37M )

    HTML:

    
    
        
        
        
            
        
    
    

    Console:

    use_jQuery();
    
    setTimeout(function() {
        $('img').css({display: 'block'});
        setTimeout(function() {
            $('img').css({display: 'none'});
        }, 1000);
    }, 2000);
    

    Same things seems to happens with CSS animation:

    Probably the element don't even render.

提交回复
热议问题