samedi 19 novembre 2016

How to link favicon to a random css color?

I'm trying to make it so my favicon is the same color as the spot color on my website. The spot color on my website randomly changes between 3 colors on every refresh (using javascript). I was almost able to get my favicons to randomly change but I am not sure how to approach linking them to specific colors in my javascript instead. Check out my website here.

HTML & PHP:
<head>
<link rel="shortcut icon" type="image/ico" href="../images/favicon_<?php echo rand(1,3); ?>.ico"/>
</head

Javascript:
var colors = ['#FFCB80', '#5A53EA', '#65CE9C'];
var random_color = colors[Math.floor(Math.random() * colors.length)];

$(document).ready(function() {

$('.tag').css('color', random_color);
$('#nav a:hover').css('color', "black");
$('#nav a:link').css('color', random_color);
$('#nav a:visited').css('color', random_color);
$('.number').css('color', random_color);




Aucun commentaire:

Enregistrer un commentaire