Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('.header-item').each(function(){
- var s=$(this).attr('style');
- s=s.replace('background: ','background-color:');
- $(this).attr('style',s);
- });
- var mouseX=0;
- var mouseY=0;
- var HexConverter = {
- hexDigits : '0123456789ABCDEF',
- dec2hex : function( dec )
- {
- return( this.hexDigits[ dec >> 4 ] + this.hexDigits[ dec & 15 ] );
- },
- hex2dec : function( hex )
- {
- return( parseInt( hex, 16 ) )
- }
- }
- $('.head-picture').mousemove(function(event) {
- mouseX=event.pageX;
- mouseY=event.pageY;
- });
- function setColor(obj,r,g,b, variation) {
- var randomColor = '#';
- var rvar=r+Math.random()*variation-variation/2;
- var gvar=g+Math.random()*variation-variation/2;
- var bvar=b+Math.random()*variation-variation/2;
- if (rvar>255) rvar=255; if (rvar<0) rvar=0;
- if (gvar>255) gvar=255; if (gvar<0) gvar=0;
- if (bvar>255) bvar=255; if (bvar<0) bvar=0;
- randomColor +=HexConverter.dec2hex( rvar);
- randomColor +=HexConverter.dec2hex( gvar);
- randomColor +=HexConverter.dec2hex( bvar);
- $(obj).attr('style','background-color:'+randomColor);
- }
- function changeColor(obj, variation) {
- var newColor = '#';
- var r,g,b;
- if (variation<50) {
- var color=$(obj).attr('style');
- var off=5;
- r= HexConverter.hex2dec(color.substring(13+off,15+off))+Math.random()*variation-variation/2;
- g= HexConverter.hex2dec(color.substring(15+off,17+off))+Math.random()*variation-variation/2;
- b= HexConverter.hex2dec(color.substring(17+off,19+off))+Math.random()*variation-variation/2;
- if (r>255) r=255; if (r<0) r=0;
- if (g>255) g=255; if (g<0) g=0;
- if (b>255) b=255; if (b<0) b=0;
- }else{
- r=Math.random()*255;
- g=Math.random()*255;
- b=Math.random()*255;
- }
- newColor +=HexConverter.dec2hex(r);
- newColor +=HexConverter.dec2hex(g);
- newColor +=HexConverter.dec2hex(b);
- $(obj).attr('style','background-color:'+newColor);
- }
- $('.header-item').mouseover(function() {
- $('.header-item').each(function(){
- var offset = $(this).offset();
- var radius=Math.abs(mouseX-offset.left);
- radius=radius;
- if (radius<255) {
- changeColor(this,(255-radius)/4);
- }
- });
- });
Add Comment
Please, Sign In to add comment