javascript - How would i add gradience to background color in a color clock? -
how add gradience background color? hours , minutes control color , seconds control gradience. pulsating effect starting center, every second making ring of color gets darker , darker.
var clock, hour, min, sec, color; function displaytime(){ clock=new date(); hour=clock.gethours(), min=clock.getminutes(), sec=clock.getseconds(); //if single digit, add 0 left if(hour<=9) hour='0'+hour; if(min<=9) min='0'+min; if(sec<=9) sec='0'+sec; color='#'+hour+min+sec; //set background color document.body.style.background= color; document.getelementbyid('time').innerhtml=""+hour+":"+min+":"+sec+""; //set interval setinterval(displaytime,1000); //} } displaytime();
#time{ font-family: 'bangers', cursive; color: white; font-size: 100px; position: relative; text-align: center; padding: 10%; }
<!doctype html> <html> <head> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="./dist/style.css"> <link href='http://fonts.googleapis.com/css?family=bangers' rel='stylesheet' type='text/css'> </head> <body> <div id="time"></div> <script type="text/javascript" src="./dist/app-browserify.js"></script> </body> </html>
you can use simple method make text gradienty:
h1 { font-size: 72px; background: -webkit-linear-gradient(#eee, #333); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-family: 'segoe ui', sans-serif; margin: 0; }
<h1>this colour</h1>
in case, can apply below styles #time
.
background: -webkit-linear-gradient(#eee, #333); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
Comments
Post a Comment