Changing background based on time of day (using javascript)

前端 未结 3 1722
无人及你
无人及你 2020-11-29 10:44

Okay, I have two different background .jpgs that I want to used as the backgroud depending on what time of day it is. I want the sunny background from 7am to 8pm and the nig

3条回答
  •  半阙折子戏
    2020-11-29 11:18

    You don't need to use a new stylesheet for each image. You can change only the background image from javascript:

    
    
        
    
    
    
    
    
    
    

    EDIT: updated to show the recommended location of the script inside the page. This has been tested and works in Firefox and Internet Explorer.

提交回复
热议问题