login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > JS > Overige > <title> Beweegt!

<title> Beweegt!

Auteur: Medewerker van LeeJoo.nl - 03 oktober 2004 - 11:23 - Gekeurd door: Dennisvb - Hits: 6875 - Aantal punten: 1.82 (11 stemmen)




Dit is echt grappig! het zorgt dat je <title>blabla</title> beweegt in allerlei verschillende stijlen...check maar!;-)

Code:
  1. <script language="JavaScript">
  2. var speed = 10
  3. var pause = 1500
  4. var timerID = null
  5. var bannerRunning = false
  6. var ar = new Array()
  7.  
  8. ar[0] = "Welcome op de site van Leejoo"
  9. ar[1] = "Hier vind je alles om je pagina dynamisch te maken"
  10. ar[2] = "kijk rustig rond ........"
  11. ar[3] = "Heb je vragen, stel ze in het gastenbook of mail me"
  12.  
  13. var message = 0
  14.  
  15. var state = ""
  16.  
  17. clearState()
  18.  
  19. function stopBanner() {
  20. // if banner is currently running
  21. if (bannerRunning)
  22. // stop the banner
  23. clearTimeout(timerID)
  24. // timer is now stopped
  25. timerRunning = false
  26. }
  27.  
  28. // start the banner
  29. function startBanner() {
  30. // make sure the banner is stopped
  31. stopBanner()
  32. // start the banner from the current position
  33. showBanner()
  34. }
  35.  
  36. // assign state a string of "0" characters of the length of the current message
  37. function clearState() {
  38. // initialize to empty string
  39. state = ""
  40. // create string of same length containing 0 digits
  41. for (var i = 0; i < ar[message].length; ++i) {
  42. state += "0"
  43. }
  44. }
  45.  
  46. // display the current message
  47. function showBanner() {
  48. // if the current message is done
  49. if (getString()) {
  50. // increment message
  51. message++
  52. // if new message is out of range wrap around to first message
  53. if (ar.length <= message)
  54. message = 0
  55. // new message is first displayed as empty string
  56. clearState()
  57. // display next character after pause milliseconds
  58. timerID = setTimeout("showBanner()", pause)
  59. }
  60. else {
  61. // initialize to empty string
  62. var str = ""
  63. // built string to be displayed (only character selected thus far are displayed)
  64. for (var j = 0; j < state.length; ++j) {
  65. str += (state.charAt(j) == "1") ? ar[message].charAt(j) : " "
  66. }
  67. document.title = str
  68. timerID = setTimeout("showBanner()", speed)
  69. }
  70. }
  71.  
  72. function getString() {
  73. // set variable to true (it will stay true unless proven otherwise)
  74. var full = true
  75. // set variable to false if a free space is found in string (a not-displayed char)
  76. for (var j = 0; j < state.length; ++j) {
  77. // if character at index j of current message has not been placed in displayed string
  78. if (state.charAt(j) == 0)
  79. full = false
  80. }
  81. // return true immediately if no space found (avoid infinitive loop later)
  82. if (full) return true
  83. // search for random until free space found (braoken up via break statement)
  84. while (1) {
  85. // a random number (between 0 and state.length - 1 == message.length - 1)
  86. var num = getRandom(ar[message].length)
  87. // if free space found break infinitive loop
  88. if (state.charAt(num) == "0")
  89. break
  90. }
  91. // replace the 0 character with 1 character at place found
  92. state = state.substring(0, num) + "1" + state.substring(num + 1, state.length)
  93. // return false because the string was not full (free space was found)
  94. return false
  95. }
  96.  
  97. function getRandom(max) {
  98. // create instance of current date
  99. var now = new Date()
  100. // create a random number (good generator)
  101. var num = now.getTime() * now.getSeconds() * Math.random()
  102. // cut random number to value between 0 and max - 1, inclusive
  103. return num % max
  104. }
  105. startBanner()
  106. // -->
  107. </script>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (10)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.024s