[JavaScript] [jQuery]彩色链接 →→→→→进入此内容的聊天室

来自 , 2021-01-06, 写在 JavaScript, 查看 103 次.
URL http://www.code666.cn/view/85d6e9c8
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
  5. <title>jQuery链接变色 — 前端观察</title>
  6. <style type="text/css">
  7. body, div {
  8. margin: 0;
  9. padding: 0;
  10. }
  11. html {
  12. font-size: 62.5%;
  13. height: 100%;
  14. background-color: #111;
  15. }
  16. body {
  17. background-color: #111;
  18. color: #eee;
  19. font: normal 1.25em/1.75em Helvetica, Arial, Verdana, sans-serif;
  20. padding: 0;
  21. margin: 50px auto;
  22. width: 70em;
  23. }
  24. strong {
  25. font-weight: bold;
  26. }
  27. a:link, a:visited {
  28. color: #fff;
  29. text-decoration: none;
  30. }
  31. a:hover {
  32. color:#999;
  33. text-decoration:underline
  34. }
  35. h1 {
  36. font-weight: normal;
  37. font-size: 2.6em;
  38. margin: 1em 0;
  39. border-bottom: 2px solid #333;
  40. color: #fff;
  41. line-height: 1.25em;
  42. }
  43. .demo {
  44. font-weight: bold;
  45. font-size: 2em;
  46. background: #0a0a0a;
  47. padding: 1em;
  48. display: inline-block;
  49. cursor:pointer;
  50. _display:inline;
  51. zoom:1;/*fuck IE6*/
  52. }
  53. a.demo:hover {
  54. text-decoration:none;
  55. }
  56. .clear {
  57. clear: both
  58. }
  59. </style>
  60. <script src="jquery.min.js" type="text/javascript" charset="utf-8"></script>
  61. <script type="text/javascript">
  62. $(document).ready(function() {
  63. $(".colorize").bind("mouseenter", function(){
  64. $(this).data("text", $(this).text());
  65. $(this).html(colorize($(this).text()));
  66. }).bind("mouseleave", function(){
  67. $(this).html($(this).data("text"));
  68. });
  69. $(".colorize2").hover(function(){
  70. $(this).data("text", $(this).text());
  71. $(this).html(colorize($(this).text()));
  72. }, function(){
  73. $(this).html($(this).data("text"));
  74. });
  75.  
  76. })
  77.  
  78. var colors = ["#ff2e99", "#ff8a2d", "#ffe12a", "#caff2a", "#1fb5ff", "#5931ff",
  79.  
  80. "#b848ff"]
  81.  
  82. function colorize(text) {
  83. var colorized = ""
  84. var bracket_color = ""
  85. for (i = 0; i < text.length; i++) {
  86. var index = Math.floor(Math.random()*7)
  87. if (text[i] == "(")
  88. bracket_color = colors[index]
  89.  
  90. color = (bracket_color.length && (text[i] == "(" || text[i] == ")")) ?
  91.  
  92. bracket_color : colors[index]
  93. colorized = colorized + '<span style="color: '+color+' !important">' +
  94.  
  95. text.charAt(i) + '</span>'
  96. }
  97. return colorized
  98. }
  99. </script>
  100. </head>
  101. <body>
  102. <h1><a href="#" _fcksavedurl="#">jQuery链接变色演示</a></h1>
  103. <a class="demo colorize" href="http://www.51xflash.com" _fcksavedurl="http://www.51xflash.com" title="鼠标放上来也会变色哦">
  104. 前端观察</a>
  105. <div class="demo colorize2" onClick="location.href='http://www.51xflash.com'">鼠标放
  106. 上去会变色,嘿嘿!</div>
  107. </body>
  108. </html>
  109.  
  110. //javascript/1071

回复 "[jQuery]彩色链接"

这儿你可以回复上面这条便签

captcha