PDA

View Full Version : rotating text around cursor


evilmonkey
03-22-2003, 08:12 PM
Ok, here is my script that is susposed to make text spin around my cursor. The top half of this script works perfectly by itself, but I would like to have two rings of text. I tried changing some of the functions of the second ring how this one tutorial instructed, but that didn't work. I dunno what I need to do to get both of them to work at the same time.


<body upload="drag();drag2()">

<SCRIPT LANGUAGE="JavaScript1.2">
<!--//

//Circling text trail- Tim Tilton
//Website: http://www.tempermedia.com/
//Visit http://www.dynamicdrive.com for this script and more

// your message here
var msg='W e l c o m e';

var font='Ravie';
var size=3; // up to seven
var color='red';

// This is not the rotation speed, its the reaction speed, keep low!
// Set this to 1 for just plain rotation w/out drag
var speed=.3;

// This is the rotation speed, set it negative if you want
// it to spin clockwise
var rotation=.1;

// Alter no variables past here!, unless you are good
//---------------------------------------------------

var ns=(document.layers);
var ie=(document.all);
var msg=msg.split('');
var n=msg.length;
var a=size*10;
var currStep=0;
var ymouse=0;
var xmouse=0;
var scrll=0;
var props="<font face="+font+" size="+size+" color="+color+">";

if (ie)
window.pageYOffset=0

// writes the message
if (ns){
for (i=0; i < n; i++)
document.write('<layer name="nsmsg'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+msg[i]+'</font></center></layer>');
}
if (ie){
document.write('<div id="outer" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < n; i++)
document.write('<div id="iemsg" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center;font-weight:regular;cursor:default">'+props+msg[i]+'</font></div>');
document.write('</div></div>');
}
(ns)?window.captureEvents(Event.MOUSEMOVE):0;

function Mouse(evnt){
ymouse = (ns)?evnt.pageY+20-(window.pageYOffset):event.y; // y-position
xmouse = (ns)?evnt.pageX+20:event.x-20; // x-position
}

if (ns||ie)
(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
y=new Array();
x=new Array();
Y=new Array();
X=new Array();
for (i=0; i < n; i++){
y[i]=0;
x[i]=0;
Y[i]=0;
X[i]=0;
}

function makecircle(){ // rotation properties
if (ie) outer.style.top=document.body.scrollTop;
currStep-=rotation;
for (i=0; i < n; i++){ // makes the circle
var d=(ns)?document.layers['nsmsg'+i]:iemsg[i].style;
d.top=y[i]+a*Math.sin((currStep+i*1)/3.8)+window.pageYOffset-10;
d.left=x[i]+a*Math.cos((currStep+i*1)/3.8)*2; // remove *2 for just a plain circle, not oval
}
}

function drag(){ // makes the resistance
scrll=(ns)?window.pageYOffset:0;
y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
for (var i=1; i < n; i++){
y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);

}
makecircle();
// not rotation speed, leave at zero
setTimeout('drag()',10);
}
if (ns||ie)window.onload=drag;

// -->
</SCRIPT>

==============================================
---------The error is probably in the script below------------
==============================================

<SCRIPT LANGUAGE="JavaScript1.2">
<!--//

//Circling text trail- Tim Tilton
//Website: http://www.tempermedia.com/
//Visit http://www.dynamicdrive.com for this script and more

// your message here
var msg='to the Joke Site!';

var font='Ravie';
var size=3; // up to seven
var color='red';

// This is not the rotation speed, its the reaction speed, keep low!
// Set this to 1 for just plain rotation w/out drag
var speed=.3;

// This is the rotation speed, set it negative if you want
// it to spin clockwise
var rotation=-.1;

// Alter no variables past here!, unless you are good
//---------------------------------------------------

var ns=(document.layers);
var ie=(document.all);
var msg=msg.split('');
var n=msg.length;
var a=size*10;
var currStep=0;
var ymouse=0;
var xmouse=0;
var scrll=0;
var props="<font face="+font+" size="+size+" color="+color+">";

if (ie)
window.pageYOffset=0

// writes the message
if (ns){
for (i=0; i < n; i++)
document.write('<layer name="nsmsg'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+msg[i]+'</font></center></layer>');
}
if (ie){
document.write('<div id="outer" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < n; i++)
document.write('<div id="iemsg" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center;font-weight:regular;cursor:default">'+props+msg[i]+'</font></div>');
document.write('</div></div>');
}
(ns)?window.captureEvents(Event.MOUSEMOVE):0;

function Mouse(evnt){
ymouse = (ns)?evnt.pageY+20-(window.pageYOffset):event.y; // y-position
xmouse = (ns)?evnt.pageX+20:event.x-20; // x-position
}

if (ns||ie)
(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
y=new Array();
x=new Array();
Y=new Array();
X=new Array();
for (i=0; i < n; i++){
y[i]=0;
x[i]=0;
Y[i]=0;
X[i]=0;
}

function makecircle2(){ // rotation properties
if (ie) outer.style.top=document.body.scrollTop;
currStep-=rotation;
for (i=0; i < n; i++){ // makes the circle
var d=(ns)?document.layers['nsmsg'+i]:iemsg[i].style;
d.top=y[i]+a*Math.sin((currStep+i*1)/3.8)+window.pageYOffset-10;
d.left=x[i]+a*Math.cos((currStep+i*1)/3.8)*2; // remove *2 for just a plain circle, not oval
}
}

function drag2(){ // makes the resistance
scrll=(ns)?window.pageYOffset:0;
y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
for (var i=1; i < n; i++){
y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);

}
makecircle2();
// not rotation speed, leave at zero
setTimeout('drag2()',10);
}
if (ns||ie)window.onload=drag2;

// -->
</SCRIPT>

A1ien51
03-23-2003, 01:27 AM
Problem with the script is that variables repeat......

evilmonkey
03-23-2003, 05:25 AM
Thnx...
I changed all the variables and now the inner circle works. However, I am still having problems with the outer circle. Here is the code where I'm not sure if I changed all of the variables correctly. Your help is very much appreciated.


<SCRIPT LANGUAGE="JavaScript1.2">
<!--//

//Circling text trail- Tim Tilton
//Website: http://www.tempermedia.com/
//Visit http://www.dynamicdrive.com for this script and more

// your message here
var msg2='to the Joke Site!';

var font2='Ravie';
var size2=3; // up to seven
var color2='red';

// This is not the rotation speed, its the reaction speed, keep low!
// Set this to 1 for just plain rotation w/out drag
var speed2=.3;

// This is the rotation speed, set it negative if you want
// it to spin clockwise
var rotation2=-.1;

// Alter no variables past here!, unless you are good
//---------------------------------------------------

var ns2=(document.layers);
var ie2=(document.all);
var msg2=msg.split('');
var n2=msg.length;
var a2=size*18;
var currStep2=0;
var ymouse2=0;
var xmouse2=0;
var scrll2=0;
var props2="<font face="+font2+" size="+size2+" color="+color2+">";

if (ie2)
window.pageYOffset=0

// writes the message
if (ns2){
for (i2=0; i2 < n2; i2++)
document.write('<layer name="nsmsg'+i2+'" top=0 left=0 height='+a2+' width='+a2+'><center>'+props2+msg[i2]+'</font></center></layer>');
}
if (ie2){
document.write('<div id="outer" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i2=0; i2 < n2; i2++)
document.write('<div id="iemsg" style="position:absolute;top:0px;left:0;height:'+a2+';width:'+a2+';text-align:center;font-weight:regular;cursor:default">'+props2+msg[i2]+'</font></div>');
document.write('</div></div>');
}
(ns2)?window.captureEvents(Event.MOUSEMOVE):0;

function Mouse(evnt2){
ymouse2 = (ns2)?evnt2.pageY+20-(window.pageYOffset):event.y; // y-position
xmouse2 = (ns2)?evnt2.pageX+20:event.x-20; // x-position
}

if (ns2||ie2)
(ns2)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
y=new Array();
x=new Array();
Y=new Array();
X=new Array();
for (i2=0; i2 < n2; i2++){
y[i2]=0;
x[i2]=0;
Y[i2]=0;
X[i2]=0;
}

function makecircle2(){ // rotation properties
if (ie2) outer.style.top=document.body.scrollTop;
currStep2-=rotation2;
for (i2=0; i2 < n2; i2++){ // makes the circle
var d2=(ns2)?document.layers['nsmsg'+i2]:iemsg[i2].style;
d2.top=y[i2]+a2*Math.sin((currStep2+i2*1)/3.8)+window.pageYOffset-10;
d2.left=x[i2]+a2*Math.cos((currStep2+i2*1)/3.8)*2; // remove *2 for just a plain circle, not oval
}
}

function drag2(){ // makes the resistance
scrll2=(ns2)?window.pageYOffset:0;
y[0]=Math.round(Y[0]+=((ymouse2)-Y[0])*speed);
x[0]=Math.round(X[0]+=((xmouse2)-X[0])*speed);
for (var i2=1; i2 < n2; i2++){
y[i2]=Math.round(Y[i2]+=(y[i2-1]-Y[i2])*speed);
x[i2]=Math.round(X[i2]+=(x[i2-1]-X[i2])*speed);

}
makecircle2();
// not rotation speed, leave at zero
setTimeout('drag2()',10);
}
if (ns2||ie2)window.onload=drag2;

// -->
</SCRIPT>

evilmonkey
03-26-2003, 04:09 AM
this post got a little letter with a black hole next to it. What does that mean?

RoyW
03-26-2003, 04:57 AM
this post got a little letter with a black hole next to it. What does that mean?

It means that you are "subscribed" to that thread and will receive emails if a new post is added, like this one :)


Some vars you have missed

y=new Array();
x=new Array();
Y=new Array();
X=new Array();
for (i2=0; i2 < n2; i2++){
y[i2]=0;
x[i2]=0;
Y[i2]=0;
X[i2]=0;

change to

y2=new Array();
x2=new Array();
Y2=new Array();
X2=new Array();
for (i2=0; i2 < n2; i2++){
y2[i2]=0;
x2[i2]=0;
Y2[i2]=0;
X2[i2]=0;



"nsmsg" to "nsmsg2"
"iemsg" to "iemsg2"

get rid of

window.onload=drag;

window.onload=drag2;


use

<body onload="drag();drag2();"


anything that has "mouse" or "Mouse" do not duplicate - you only have one mouse on your computer.

This will help some but it is still going to be an uphill task to have 2 rotating texts using that script.

evilmonkey
03-29-2003, 05:39 AM
Thnx. I changed the variable and the body onload thing. However, i think i may have deleted more than I should have or not enough of the mouse code. I am pretty sure that's what's wrong right now. What should i do about that code?


var ns2=(document.layers);
var ie2=(document.all);
var msg2=msg.split('');
var n2=msg.length;
var a2=size*18;
var currStep2=0;
var ymouse2=0;
var xmouse2=0;
var scrll2=0;
var props2="<font face="+font2+" size="+size2+" color="+color2+">";

if (ie2)
window.pageYOffset=0

// writes the message
if (ns2){
for (i2=0; i2 < n2; i2++)
document.write('<layer name="nsmsg'+i2+'" top=0 left=0 height='+a2+' width='+a2+'><center>'+props2+msg[i2]+'</font></center></layer>');
}
if (ie2){
document.write('<div id="outer" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i2=0; i2 < n2; i2++)
document.write('<div id="iemsg2" style="position:absolute;top:0px;left:0;height:'+a2+';width:'+a2+';text-align:center;font-weight:regular;cursor:default">'+props2+msg[i2]+'</font></div>');
document.write('</div></div>');
}

if (ns2||ie2)
y2=new Array();
x2=new Array();
Y2=new Array();
X2=new Array();
for (i2=0; i2 < n2; i2++){
y2[i2]=0;
x2[i2]=0;
Y2[i2]=0;
X2[i2]=0;
}

function makecircle2(){ // rotation properties
if (ie2) outer.style.top=document.body.scrollTop;
currStep2-=rotation2;
for (i2=0; i2 < n2; i2++){ // makes the circle
var d2=(ns2)?document.layers['nsmsg2'+i2]:iemsg[i].style;
d2.top=y2[i2]+a2*Math.sin((currStep2+i2*1)/3.8)+window.pageYOffset-10;
d2.left=x2[i2]+a2*Math.cos((currStep2+i2*1)/3.8)*2; // remove *2 for just a plain circle, not oval
}
}

function drag2(){ // makes the resistance
scrll2=(ns2)?window.pageYOffset:0;
y2[0]=Math.round(Y2[0]+=((ymouse2)-Y2[0])*speed);
x2[0]=Math.round(X2[0]+=((xmouse2)-X2[0])*speed);
for (var i2=1; i2 < n2; i2++){
y2[i2]=Math.round(Y2[i2]+=(y2[i2-1]-Y2[i2])*speed);
x2[i2]=Math.round(X2[i2]+=(x2[i2-1]-X2[i2])*speed);

}
makecircle2();
// not rotation speed, leave at zero
setTimeout('drag2()',10);
}
if (ns2||ie2)<body onload="drag();drag2()">

// -->
</SCRIPT>

RoyW
03-29-2003, 10:28 PM
You need to use the mouseX and Y from the first script


y2[0]=Math.round(Y2[0]+=((ymouse2)-Y2[0])*speed);
x2[0]=Math.round(X2[0]+=((xmouse2)-X2[0])*speed);

change to

y2[0]=Math.round(Y2[0]+=((ymouse)-Y2[0])*speed);
x2[0]=Math.round(X2[0]+=((xmouse)-X2[0])*speed);

also
document.write('<div id="outer2" style="position:absolute;top:0px;left:0px"><div style="position:relative">');