Created
August 5, 2012 09:38
-
-
Save kzar/3263441 to your computer and use it in GitHub Desktop.
http://intheface.me/ colour changing JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if((!jQuery.browser.msie)||(jQuery.browser.msie&&jQuery.browser.version.substring(0,1)>9)){jQuery(document).ready(setInterval(function(){changeSiteColor(jQuery('#logo, #menu-menu a, #col-itf .heading, #col-itf .more-link, #col-itf .view-page, .title, .current, #signup, .social'),jQuery('#col-itf .tri, #col-itf .tri-readmore'),jQuery('#col-releases .heading, #col-releases .more-link, #col-releases .view-page, #col-mixes .heading, #col-mixes .more-link, #col-mixes .view-page, #col-single .heading'),jQuery('#col-releases .tri, #col-releases .tri-readmore, #col-mixes .tri, #col-mixes .tri-readmore, #col-single .tri'))},11000));function changeSiteColor(backgroundsA,bordersA,backgroundsB,bordersB){var colorA='rgb('+randRange(0,200)+','+randRange(0,200)+','+randRange(0,200)+')';var darkerA=darkerColor(colorA,.4);var colorB=lighterColor(colorA,.3);var darkerB=darkerColor(colorB,.4);backgroundsA.css('background-color',colorA);bordersA.css('border-top-color',darkerA);backgroundsB.css('background-color',colorB);bordersB.css('border-top-color',darkerB);} | |
| function randRange(lowVal,highVal){return Math.floor(Math.random()*(highVal-lowVal+1))+lowVal;};var lighterColor=function(color,ratio){return changeColor(color,ratio,false);};var darkerColor=function(color,ratio){return changeColor(color,ratio,true);};var changeColor=function(color,ratio,darker){color=color.replace(/^\s*|\s*$/,'');color=color.replace(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i,'#$1$1$2$2$3$3');var difference=Math.round(ratio*256)*(darker?-1:1),rgb=color.match(new RegExp('^rgba?\\(\\s*'+'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'+'\\s*,\\s*'+'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'+'\\s*,\\s*'+'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'+'(?:\\s*,\\s*'+'(0|1|0?\\.\\d+))?'+'\\s*\\)$','i')),alpha=!!rgb&&rgb[4]!=null?rgb[4]:null,decimal=!!rgb?[rgb[1],rgb[2],rgb[3]]:color.replace(/^#?([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i,function(){return parseInt(arguments[1],16)+','+parseInt(arguments[2],16)+','+parseInt(arguments[3],16);}).split(/,/),returnValue;return!!rgb?'rgb'+(alpha!==null?'a':'')+'('+Math[darker?'max':'min'](parseInt(decimal[0],10)+difference,darker?0:255)+', '+Math[darker?'max':'min'](parseInt(decimal[1],10)+difference,darker?0:255)+', '+Math[darker?'max':'min'](parseInt(decimal[2],10)+difference,darker?0:255)+(alpha!==null?', '+alpha:'')+')':['#',pad(Math[darker?'max':'min'](parseInt(decimal[0],10)+difference,darker?0:255).toString(16),2),pad(Math[darker?'max':'min'](parseInt(decimal[1],10)+difference,darker?0:255).toString(16),2),pad(Math[darker?'max':'min'](parseInt(decimal[2],10)+difference,darker?0:255).toString(16),2)].join('');};var pad=function(num,totalChars){var pad='0';num=num+'';while(num.length<totalChars){num=pad+num;} | |
| return num;};} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!jQuery.browser.msie || jQuery.browser.version.substring(0, 1) > 9) { | |
| function pad(num, totalChars) { | |
| var padding = new Array(totalChars - num.length).join("0"); | |
| return padding + num; | |
| } | |
| function changeColor(color, ratio, darker) { | |
| color = color.replace(/^\s*|\s*$/,''); | |
| color = color.replace(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i,'#$1$1$2$2$3$3'); | |
| var difference = Math.round(ratio * 256) * (darker?-1:1), | |
| rgb = color.match(new RegExp('^rgba?\\(\\s*'+'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'+'\\s*,\\s*'+'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'+'\\s*,\\s*'+'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'+'(?:\\s*,\\s*'+'(0|1|0?\\.\\d+))?'+'\\s*\\)$','i')), | |
| alpha = !!rgb && rgb[4]!=null?rgb[4]:null,decimal=!!rgb?[rgb[1],rgb[2],rgb[3]]:color.replace(/^#?([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i, function() { | |
| return parseInt(arguments[1], 16) + ',' + parseInt(arguments[2], 16) + ',' + parseInt(arguments[3], 16); | |
| }).split(/,/), | |
| returnValue; | |
| return !! rgb ? 'rgb'+(alpha!==null?'a':'') + '(' + Math[darker?'max':'min'](parseInt(decimal[0],10)+difference,darker?0:255)+', '+Math[darker?'max':'min'](parseInt(decimal[1],10)+difference,darker?0:255)+', '+Math[darker?'max':'min'](parseInt(decimal[2],10)+difference,darker?0:255)+(alpha!==null?', '+alpha:'')+')':['#',pad(Math[darker?'max':'min'](parseInt(decimal[0],10)+difference,darker?0:255).toString(16),2),pad(Math[darker?'max':'min'](parseInt(decimal[1],10)+difference,darker?0:255).toString(16),2),pad(Math[darker?'max':'min'](parseInt(decimal[2],10)+difference,darker?0:255).toString(16),2)].join(''); | |
| } | |
| function darkerColor(color, ratio) { | |
| return changeColor(color,ratio,true); | |
| } | |
| function lighterColor(color, ratio) { | |
| return changeColor(color,ratio,false); | |
| } | |
| function randRange(lowVal, highVal) { | |
| return Math.floor(Math.random() * (highVal-lowVal + 1)) + lowVal; | |
| } | |
| function changeSiteColor(backgroundsA, bordersA, backgroundsB, bordersB) { | |
| var colorA='rgb('+randRange(0,200)+','+randRange(0,200)+','+randRange(0,200)+')'; | |
| var darkerA=darkerColor(colorA,.4); | |
| var colorB=lighterColor(colorA,.3); | |
| var darkerB=darkerColor(colorB,.4); | |
| backgroundsA.css('background-color',colorA); | |
| bordersA.css('border-top-color',darkerA); | |
| backgroundsB.css('background-color',colorB); | |
| bordersB.css('border-top-color',darkerB); | |
| } | |
| jQuery(document).ready(setInterval(function () { | |
| changeSiteColor(jQuery('#logo, #menu-menu a, #col-itf .heading, #col-itf .more-link, #col-itf .view-page, .title, .current, #signup, .social'),jQuery('#col-itf .tri, #col-itf .tri-readmore'), | |
| jQuery('#col-releases .heading, #col-releases .more-link, #col-releases .view-page, #col-mixes .heading, #col-mixes .more-link, #col-mixes .view-page, #col-single .heading'), | |
| jQuery('#col-releases .tri, #col-releases .tri-readmore, #col-mixes .tri, #col-mixes .tri-readmore, #col-single .tri')) | |
| }, 11000)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment