/* Sine scrolling text script By Mark Baker (mark.baker@usa.net) Permission granted to Dynamicdrive.com to include script in archive For 100's of free DHTML scripts, visit Dynamicdrive.com */ // globals var initialx, initialy, scrolltext; var frame = 0, frame2 = 0.5; var amplitude1 = 50, amplitude2 = 30; var offset = 0.2, speed = 0.2, speed2 = 0.35; var offset2 = 0.6; var scrollspeed = 6; var charwidth = 30; var twopi = Math.PI * 2; var chracters, position, numvisible, nextchar, firstchar; var skipsteps = 1; var delaytimer = 0; var interval; // function to create sine scroller function sinescroll (x, y, value, number_of_chars) { // setup globals scrolltext = new String(value); initialx = x; initialy = y; numvisible = number_of_chars; nextchar = numvisible; firstchar = 0; // create fixed-size arrays of characters and positions characters = new Array(numvisible); position = initialx; // write DIVs to hold characters for (var i = 0; i < numvisible; i++) { document.write('
', scrolltext.charAt(i), '
' + scrolltext.charAt(nextchar) + '
'; // update nextchar nextchar++; // check for wrap-around if (nextchar >= scrolltext.length) { nextchar = 0; } // change position and counters by offset position += charwidth; frame += offset; frame2 += offset2; // update firstchar firstchar++; if (firstchar >= numvisible) { firstchar = 0; } } // wrap-around counters if (frame > twopi) frame -= twopi; if (frame2 > twopi) frame2 -= twopi; // set up loop variables var angle = frame; var angle2 = frame2; var pos = position; // update the html for (var i=firstchar; i < numvisible; i++) { characters[i].style.left = pos; characters[i].style.top = initialy + amplitude1 * Math.sin(angle) + amplitude2 * Math.sin(angle2); angle += offset; angle2 += offset2; pos += charwidth; } for (var i=0; i < firstchar; i++) { characters[i].style.left = pos; characters[i].style.top = initialy + amplitude1 * Math.sin(angle) + amplitude2 * Math.sin(angle2); angle += offset; angle2 += offset2; pos += charwidth; } } // start the animation function start () { if (!document.all) return // get all of the DIV tags into an array (IE only?) characters = document.all.item('character'); // setup timeout to call this function again interval = window.setInterval("step();", 20); } // stop the animation function stop () { if (!document.all) return if (interval) clearInterval(interval); } window.onload=start window.onunload=stop // create the scroller if (document.all) sinescroll(30, 100, " **** Happy Birthday to You Have a great day Do anything you want to do May all your dreams come true and may this be the first day of the happiest years of your life **** ", 15);