A way to create random-noise background image (png) with javascript?

后端 未结 4 1160
Happy的楠姐
Happy的楠姐 2021-02-09 02:31

The new layout of YouTube added a background random-noise which I like very much, having seen almost exactely the same effect on other sites, so I plan to use the same technique

4条回答
  •  感情败类
    2021-02-09 03:26

    You can use CSS to display this image:

    #someimageselector {
        background: white url('data:image/png;base64,iVBOR...lots of data') repeat scroll left top;
    }
    

    You can change the initial color of your background by editing the value white.

    To set CSS with JavaScript, set the background property of an element:

    document.getElementByID("someimageselector").background = 'white url(data:image/png....';
    

提交回复
热议问题