Guest User

Untitled

a guest
Feb 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $('.header-item').each(function(){
  2.     var s=$(this).attr('style');
  3.     s=s.replace('background: ','background-color:');
  4.     $(this).attr('style',s);
  5. });
  6.  
  7. var mouseX=0;
  8. var mouseY=0;
  9.  
  10. var HexConverter = {
  11.     hexDigits : '0123456789ABCDEF',
  12.  
  13.     dec2hex : function( dec )
  14.     {
  15.         return( this.hexDigits[ dec >> 4 ] + this.hexDigits[ dec & 15 ] );
  16.     },
  17.  
  18.     hex2dec : function( hex )
  19.     {
  20.         return( parseInt( hex, 16 ) )
  21.     }
  22. }
  23.  
  24. $('.head-picture').mousemove(function(event) {
  25.     mouseX=event.pageX;
  26.     mouseY=event.pageY;
  27. });
  28.  
  29. function setColor(obj,r,g,b, variation) {
  30.     var randomColor = '#';
  31.         var rvar=r+Math.random()*variation-variation/2;
  32.         var gvar=g+Math.random()*variation-variation/2;
  33.         var bvar=b+Math.random()*variation-variation/2;
  34.        
  35.         if (rvar>255) rvar=255; if (rvar<0) rvar=0;
  36.         if (gvar>255) gvar=255; if (gvar<0) gvar=0;
  37.         if (bvar>255) bvar=255; if (bvar<0) bvar=0;
  38.  
  39.         randomColor +=HexConverter.dec2hex( rvar);
  40.         randomColor +=HexConverter.dec2hex( gvar);
  41.         randomColor +=HexConverter.dec2hex( bvar);     
  42.         $(obj).attr('style','background-color:'+randomColor);
  43. }
  44.  
  45. function changeColor(obj, variation) {
  46.     var newColor = '#';
  47.     var r,g,b;
  48.         if (variation<50) {
  49.         var color=$(obj).attr('style');
  50.         var off=5;
  51.          r= HexConverter.hex2dec(color.substring(13+off,15+off))+Math.random()*variation-variation/2;
  52.          g= HexConverter.hex2dec(color.substring(15+off,17+off))+Math.random()*variation-variation/2;
  53.          b= HexConverter.hex2dec(color.substring(17+off,19+off))+Math.random()*variation-variation/2;      
  54.                    
  55.         if (r>255) r=255; if (r<0) r=0;
  56.         if (g>255) g=255; if (g<0) g=0;
  57.         if (b>255) b=255; if (b<0) b=0;
  58.         }else{
  59.             r=Math.random()*255;
  60.              g=Math.random()*255;
  61.              b=Math.random()*255;
  62.         }
  63.         newColor +=HexConverter.dec2hex(r);
  64.         newColor +=HexConverter.dec2hex(g);
  65.         newColor +=HexConverter.dec2hex(b);    
  66.         $(obj).attr('style','background-color:'+newColor);
  67. }
  68.  
  69. $('.header-item').mouseover(function() {       
  70.         $('.header-item').each(function(){
  71.             var offset = $(this).offset();
  72.             var radius=Math.abs(mouseX-offset.left);
  73.             radius=radius;
  74.             if (radius<255) {
  75.                 changeColor(this,(255-radius)/4);
  76.             }
  77.             });
  78.     });
Add Comment
Please, Sign In to add comment