PradaThemes

Floating text cursor

Jul 28th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <script language="javascript">
  2. var text='YOUR TEXT HERE';
  3. var delay=40; // speed of trail
  4. var Xoff=16; // pixel count from the left of the cursor (- values go to left)
  5. var Yoff=0; // pixel count from the top of the cursor (- values go up)
  6. var txtw=10; // amount of pixel space each character occupies
  7. var beghtml='<font color="#000000"><b>'; // optional html code that effects whole text string such as font color, size, etc.
  8. var endhtml='</b></font>';
  9. ns4 = (navigator.appName.indexOf("Netscape")>=0 && document.layers)? true : false;
  10. ie4 = (document.all && !document.getElementById)? true : false;
  11. ie5 = (document.all && document.getElementById)? true : false;
  12. ns6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
  13. var txtA=new Array();
  14. text=text.split('');
  15. var x1=0;
  16. var y1=-1000;
  17. var t='';
  18. for(i=1;i<=text.length;i++){
  19. t+=(ns4)? '<layer left="0" top="-100" width="'+txtw+'" name="txt'+i+'" height="1">' : '<div id="txt'+i+'" style="position:absolute; top:-100px; left:0px; height:1px; width:'+txtw+'; visibility:visible;">';
  20. t+=beghtml+text[i-1]+endhtml;
  21. t+=(ns4)? '</layer>' : '</div>';
  22. }
  23. document.write(t);
  24. function moveid(id,x,y){
  25. if(ns4)id.moveTo(x,y);
  26. else{
  27. id.style.left=x+'px';
  28. id.style.top=y+'px';
  29. }}
  30. function animate(evt){
  31. x1=Xoff+((ie4||ie5)?event.clientX+document.body.scrollLeft:evt.pageX);
  32. y1=Yoff+((ie4||ie5)?event.clientY+document.body.scrollTop:evt.pageY);
  33. }
  34. function getidleft(id){
  35. if(ns4)return id.left;
  36. else return parseInt(id.style.left);
  37. }
  38. function getidtop(id){
  39. if(ns4)return id.top;
  40. else return parseInt(id.style.top);
  41. }
  42. function getwindowwidth(){
  43. if(ie4||ie5)return document.body.clientWidth+document.body.scrollLeft;
  44. else return window.innerWidth+pageXOffset;
  45. }
  46. function movetxts(){
  47. for(i=text.length;i>1;i=i-1){
  48. if(getidleft(txtA[i-1])+txtw*2>=getwindowwidth()){
  49. moveid(txtA[i-1],0,-1000);
  50. moveid(txtA[i],0,-1000);
  51. }else moveid(txtA[i], getidleft(txtA[i-1])+txtw, getidtop(txtA[i-1]));
  52. }
  53. moveid(txtA[1],x1,y1);
  54. }
  55. window.onload=function(){
  56. for(i=1;i<=text.length;i++)txtA[i]=(ns4)?document.layers['txt'+i]:(ie4)?document.all['txt'+i]:document.getElementById('txt'+i);
  57. if(ns4)document.captureEvents(Event.MOUSEMOVE);
  58. document.onmousemove=animate;
  59. setInterval('movetxts()',delay);
  60. }
  61. </script>
Add Comment
Please, Sign In to add comment