Guest User

Untitled

a guest
Feb 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  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 ani() {
  30. $('.header-item').each(function(){
  31. changeColor(this, 10);
  32. });
  33. setTimeout(ani,50);
  34. }
  35. ani() ;
  36.  
  37. function changeColor(obj, variation) {
  38. var newColor = '#';
  39. var r,g,b;
  40. if (variation<50) {
  41. var color=$(obj).attr('style');
  42. var off=5;
  43. r= HexConverter.hex2dec(color.substring(13+off,15+off))+Math.random()*variation-variation/2.2;
  44. g= HexConverter.hex2dec(color.substring(15+off,17+off))+Math.random()*variation-variation/2.2;
  45. b= HexConverter.hex2dec(color.substring(17+off,19+off))+Math.random()*variation-variation/2.2;
  46.  
  47. if (r>255) r=255; if (r<0) r=0;
  48. if (g>255) g=255; if (g<0) g=0;
  49. if (b>255) b=255; if (b<0) b=0;
  50. }else{
  51. r=Math.random()*255;
  52. g=Math.random()*255;
  53. b=Math.random()*255;
  54. }
  55. newColor +=HexConverter.dec2hex(r);
  56. newColor +=HexConverter.dec2hex(g);
  57. newColor +=HexConverter.dec2hex(b);
  58. $(obj).attr('style','background-color:'+newColor);
  59. }
  60.  
  61. $('.header-item').mouseover(function() {
  62. $('.header-item').each(function(){
  63. var offset = $(this).offset();
  64. var radius=Math.abs(mouseX-offset.left);
  65. radius=radius;
  66. if (radius<255) {
  67. changeColor(this,(255-radius)/4);
  68. }
  69. });
  70. });
Add Comment
Please, Sign In to add comment