card.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. $(document).ready(function(){
  2. $("a").hover(function() {
  3. var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
  4. $(this).stop().animate({ color: col}, 600); },
  5. function() {
  6. $(this).stop().animate({ color: col}, 400);
  7. });
  8. });
  9. /*
  10. * jQuery Color Animations
  11. * Copyright 2007 John Resig
  12. * Released under the MIT and GPL licenses.
  13. */
  14. (function(jQuery){
  15. // We override the animation for all of these color styles
  16. jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
  17. jQuery.fx.step[attr] = function(fx){
  18. if ( !fx.colorInit ) {
  19. fx.start = getColor( fx.elem, attr );
  20. fx.end = getRGB( fx.end );
  21. fx.colorInit = true;
  22. }
  23. fx.elem.style[attr] = "rgb(" + [
  24. Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
  25. Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
  26. Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
  27. ].join(",") + ")";
  28. }
  29. });
  30. // Color Conversion functions from highlightFade
  31. // By Blair Mitchelmore
  32. // http://jquery.offput.ca/highlightFade/
  33. // Parse strings looking for color tuples [255,255,255]
  34. function getRGB(color) {
  35. var result;
  36. // Check if we're already dealing with an array of colors
  37. if ( color && color.constructor == Array && color.length == 3 )
  38. return color;
  39. // Look for rgb(num,num,num)
  40. if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
  41. return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
  42. // Look for rgb(num%,num%,num%)
  43. if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
  44. return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
  45. // Look for #a0b1c2
  46. if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
  47. return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
  48. // Look for #fff
  49. if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
  50. return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
  51. // Look for rgba(0, 0, 0, 0) == transparent in Safari 3
  52. if (result = /rgba\(0, 0, 0, 0\)/.exec(color))
  53. return colors['transparent'];
  54. // Otherwise, we're most likely dealing with a named color
  55. return colors[jQuery.trim(color).toLowerCase()];
  56. }
  57. function getColor(elem, attr) {
  58. var color;
  59. do {
  60. color = jQuery.curCSS(elem, attr);
  61. // Keep going until we find an element that has color, or we hit the body
  62. if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
  63. break;
  64. attr = "backgroundColor";
  65. } while ( elem = elem.parentNode );
  66. return getRGB(color);
  67. };
  68. // Some named colors to work with
  69. // From Interface by Stefan Petre
  70. // http://interface.eyecon.ro/
  71. var colors = {
  72. aqua:[0,255,255],
  73. azure:[240,255,255],
  74. beige:[245,245,220],
  75. black:[0,0,0],
  76. blue:[0,0,255],
  77. brown:[165,42,42],
  78. cyan:[0,255,255],
  79. darkblue:[0,0,139],
  80. darkcyan:[0,139,139],
  81. darkgrey:[169,169,169],
  82. darkgreen:[0,100,0],
  83. darkkhaki:[189,183,107],
  84. darkmagenta:[139,0,139],
  85. darkolivegreen:[85,107,47],
  86. darkorange:[255,140,0],
  87. darkorchid:[153,50,204],
  88. darkred:[139,0,0],
  89. darksalmon:[233,150,122],
  90. darkviolet:[148,0,211],
  91. fuchsia:[255,0,255],
  92. gold:[255,215,0],
  93. green:[0,128,0],
  94. indigo:[75,0,130],
  95. khaki:[240,230,140],
  96. lightblue:[173,216,230],
  97. lightcyan:[224,255,255],
  98. lightgreen:[144,238,144],
  99. lightgrey:[211,211,211],
  100. lightpink:[255,182,193],
  101. lightyellow:[255,255,224],
  102. lime:[0,255,0],
  103. magenta:[255,0,255],
  104. maroon:[128,0,0],
  105. navy:[0,0,128],
  106. olive:[128,128,0],
  107. orange:[255,165,0],
  108. pink:[255,192,203],
  109. purple:[128,0,128],
  110. violet:[128,0,128],
  111. red:[255,0,0],
  112. silver:[192,192,192],
  113. white:[255,255,255],
  114. yellow:[255,255,0],
  115. transparent: [255,255,255]
  116. };
  117. })(jQuery);