User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,505 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,772 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Dec 22nd, 2004
Views: 3,891
You probably have seen those message snakes following the cursor on a web page. Well, the javascript code is not too complex, so let's look at it ...
javascript Syntax | 4 stars
  1. <!-- Experiments with style vegaseat 6/15/2002 -->
  2.  
  3. <html>
  4. <head>
  5.  
  6. <title>Message snake follows cursor</title>
  7.  
  8. <style>
  9. .spanstyle {
  10. position:absolute;
  11. visibility:visible;
  12. top:-50px;
  13. font-size:8pt;
  14. font-family:comic sans ms;
  15. font-weight:bold;
  16. color:green;
  17. }
  18. </style>
  19.  
  20. <SCRIPT LANGUAGE="JavaScript">
  21. <!-- Begin hide from older browsers
  22.  
  23. // make a message snake to follow the cursor
  24.  
  25. var x,y
  26. var step=20
  27. var flag=0
  28.  
  29. var message = "Holy Fryer! "
  30. message = message.split("")
  31.  
  32. var xpos = new Array()
  33. for (i = 0; i <= message.length-1; i++) {
  34. xpos[i]=-50
  35. }
  36.  
  37. var ypos = new Array()
  38. for (i = 0; i <= message.length-1; i++) {
  39. ypos[i]=-50
  40. }
  41.  
  42. function handlerMM(e){
  43. x = (document.layers) ? e.pageX : document.body.scrollLeft+event.clientX
  44. y = (document.layers) ? e.pageY : document.body.scrollTop+event.clientY
  45. flag=1
  46. }
  47.  
  48. function makesnake()
  49. {
  50. if (flag == 1 && document.all) {
  51. for (i = message.length-1; i >= 1; i--) {
  52. xpos[i] = xpos[i-1]+step
  53. ypos[i] = ypos[i-1]
  54. }
  55. xpos[0] = x+step
  56. ypos[0] = y
  57. for (i = 0; i < message.length-1; i++) {
  58. var thisspan = eval("span" + (i) + ".style")
  59. thisspan.posLeft = xpos[i]
  60. thisspan.posTop = ypos[i]
  61. }
  62. }
  63. else if (flag == 1 && document.layers) {
  64. for (i = message.length-1; i >= 1; i--) {
  65. xpos[i] = xpos[i-1]+step
  66. ypos[i] = ypos[i-1]
  67. }
  68. xpos[0] = x+step
  69. ypos[0] = y
  70. for (i = 0; i < message.length-1; i++) {
  71. var thisspan = eval("document.span"+i)
  72. thisspan.left = xpos[i]
  73. thisspan.top = ypos[i]
  74. }
  75. }
  76. var timer = setTimeout("makesnake()", 30)
  77. }
  78.  
  79. for (i = 0; i <= message.length-1; i++) {
  80. document.write("<span id='span"+i+"' class='spanstyle'>");
  81. document.write(message[i]);
  82. document.write("</span>")
  83. }
  84.  
  85. if (document.layers) {
  86. document.captureEvents(Event.MOUSEMOVE);
  87. }
  88. document.onmousemove = handlerMM;
  89.  
  90. // End hide from old browsers -->
  91. </script>
  92.  
  93. </head>
  94. <body bgcolor="#CCFF99" text="#330099" onLoad="makesnake()">
  95.  
  96. <H2>Why Did the Chicken Cross the Road?</H2>
  97. <br>
  98. KINDERGARTEN TEACHER: To get to the other side
  99. <br><br>
  100. PLATO: For the greater good.
  101. <br><br>
  102. ARISTOTLE: It is the nature of chickens to cross roads.
  103. <br><br>
  104. KARL MARX: It was a historical inevitability.
  105. <br><br>
  106. TIMOTHY LEARY: Because that's the only trip the establishment could let it
  107. take.
  108. <br><br>
  109. RONALD REAGAN: I forget.
  110. <br><br>
  111. CAPTAIN JAMES T. KIRK: To boldly go where no chicken has gone before.
  112. <br><br>
  113. HIPPOCRATES: Because of an excess of phlegm in its pancreas.
  114. <br><br>
  115. LOUIS FARRAKHAN: The road, you see, represents the black man. The chicken
  116. <br>'crossed' the black man in order to trample him and keep him down.
  117. <br><br>
  118. MARTIN LUTHER KING, JR.: I envision a world where all chickens will be
  119. <br>free to cross roads without having their motives called into question.
  120. <br><br>
  121. MOSES: And God came down from the Heavens, and He said unto the chicken,
  122. <br>"Thou shalt cross the road." And the chicken crossed the road, and there
  123. <br>was much rejoicing.
  124. <br><br>
  125. RICHARD M. NIXON: The chicken did not cross the road. I repeat, the
  126. <br>chicken did NOT cross the road.
  127. <br><br>
  128. FREUD: The fact that you are at all concerned that the chicken crossed
  129. <br>the road reveals your underlying sexual insecurity.
  130. <br><br>
  131. DARWIN: Chickens, over great periods of time, have been
  132. <br>naturally selected in such a way that they are now genetically
  133. <br>dispositioned to cross roads.
  134. <br><br>
  135. EINSTEIN: Whether the chicken crossed the road or the road moved beneath
  136. <br>the chicken depends upon your frame of reference.
  137. <br><br>
  138. BUDDHA: Asking this question denies your own chicken nature.
  139. <br><br>
  140. ERNEST HEMINGWAY: To die. In the rain.
  141. <br><br>
  142. ANDERSEN CONSULTING: Deregulation of the chicken's side of the road was
  143. <br>threatening its dominant market position. The chicken was faced with
  144. <br>significant challenges to create and develop the competencies required
  145. <br>for the newly competitive market. Andersen Consulting, in a partnering
  146. <br>relationship with the client, helped the chicken by rethinking its
  147. <br>physical distribution strategy and implementation processes. Using the
  148. <br>Poultry Integration Model (PIM), Andersen helped the chicken use its
  149. <br>skills, methodologies, knowledge, capital and experiences to align the
  150. <br>chicken's people, processes and technology in support of its overall
  151. <br>strategy within a Program Management framework. Andersen Consulting
  152. <br>convened a diverse cross-spectrum of road analysts and best chickens
  153. <br>along with Anderson consultants with deep skills in the transportation
  154. <br>industry to engage in a two-day itinerary of meetings in order to
  155. <br>leverage their personal knowledge capital, both tacit and explicit, and
  156. <br>to enable them to synergize with each other in order to achieve the
  157. <br>implicit goals of delivering and successfully architecting and
  158. <br>implementing an enterprise-wide value framework across the continuum of
  159. <br>poultry cross-median processes. The meeting was held in a park-like
  160. <br>setting, enabling and creating an impactful environment which was
  161. <br>strategically based, industry- focused, and built upon a consistent,
  162. <br>clear, and unified market message and aligned with the chicken's mission,
  163. <br>vision, and core values. This was conducive towards the creation of a
  164. <br>total business integration solution. Andersen Consulting helped the
  165. <br>chicken change to become more successful.
  166. <br><br>
  167. COLONEL SANDERS: I missed one?
  168.  
  169. </body>
  170. </html>
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 5:43 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC