/    Sign up×
Community /Pin to ProfileBookmark

moving text around

Hello all,

I am moving text around using “getElementById” with CSS:
#elementID {position: absolute; top…} Ok, I’ll give you the code in just a second. Well, I wanted to rotate text in a circle, but with my elementary javascript experience, I’d better stick to straight lines for now. First, I tried writing 4 separate functions for each direction. We’ll start 50px from left, increase the left by one until we get to 150, then increase top by one, and go around the square-like coordinates. I was getting some strange behavior calling one function from another. I am sure we could do that but I went a different route and tried this:

<!DOCTYPE HTML PUBLIC “-//w3c/DTD HTML 4.01 TRANSITIONAL//EN”
http://www.w3.org/TR/html4/loose.dtd“>

<html>
<head>
<title></title>

<style>
#a2{

position: absolute;
left: 50px;
top: 0px;

font-size: 32px;
color: #555599;
}

</style>

<script type=”text/javascript”>

function a2over(x1, y1, x2, y2){

var c=(x1);
var txt2 = document.getElementById(“a2”);
txt2.style.left = c;
if (x1<150) x1+=1;
setTimeout(‘a2over(‘+x1+’)’,10);
while (x1==150) {
var d=(y1);
var txt3 = document.getElementById(“a2”)
txt3.style.top = d;
if (y1<150) d+=1;
setTimeout(‘a2over(‘+y1+’)’, 10);

}
}

</script>

</head>
<body>
<p id=”a2″>P</p>
<script type=”text/javascript”>a2over(50)</script>

</body>
</html>

Would somebody be so kind as to shine some light on the best way to accomplish what I am doing here?

Also, if you wouldn’t mind telling me why we get the “invalid argument” error at line: “txt3.style.top = d;” , I’d really appreciate it.

Thanks 🙂

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JMRKEROct 11.2011 — Is this what you have in mind?

See: http://www.vicsjavascripts.org.uk/ElementEllipseII/ElementEllipseII.htm

This moves<img> tags, but you could just a easily move <div> tags of text.
Copy linkTweet thisAlerts:
@vb2javaauthorOct 11.2011 — Hello JMRKER,

Yes, I've had something like that in mind. Thank you for the link :-)
Copy linkTweet thisAlerts:
@JMRKEROct 11.2011 — You're most welcome.

Happy coding!
Copy linkTweet thisAlerts:
@vb2javaauthorOct 11.2011 — Hello again,

As the link that JRMRKER has posted is helpful, I am still at a road block. I am unsure of how to proceed with my script. I am going to ask a different way here:

Lets take 4 points. left = x and top = y

Point A: left 50, top 50

Point B: left 100, top 50

Point C: left 100, top 100

Point D: left 50, top 100

We do not need to use the "<div>" tag. We can manipulate the top and left attributes of whatever tag accepts "position: absolute;". So I am using the "<p>" tag and defining the attributes in a style sheet. Then I am using javascript to move a letter around the 4 points like the ones stated above. Later, I was going to bring in a whole bunch of letters from far left (like -100) outside the viewable part of the page. I would have the letters come into view, go around the points and then slide into their designated permanent position.

For example: Take the word "Building". I would bring in the letters backwards (meaning I would start with the "g" and not the "B") because the "g" would be the left most letter. So it would come in from far left, go around the four points once (or twice, or three times), and ect... Sounds like fun to me, but I am a beginner so it will take baby steps.

So I am just starting with "Point A". I am stuck at the second movement. I can move the letter "P" from left 50, to left 100 on the top 50 line. I do this here:

function a1(pos){

var c=(pos);

var txt2 = document.getElementById("a1");

txt2.style.left = c;
if (pos<100) pos+=1;
setTimeout('a1('+pos+')',10);

}


Ok, now should I write four separate functions for each direction, or should I write 4 separate arguments to the function? [B]AND[/B] it doesn't seem to matter which way I choose, because I am not doing something right.

I was thinking of going the 4 arguments route like the script in my original question. When I get to the [B][I]while[/I][/B] loop, I get an invalid argument error. I certainly looks like a valid argument to me especially since I just used almost the exact same argument and it works fine.

At first, I tried to use the same variable "txt2", which was already set equal to "document.getElementById ("a2"), and say txt2.style.[B][I]top[/I][/B].

Maybe this is a bad spot to use "while". I tried the "if" conditional, I can't get it to work.

Will someone help me please?
×

Success!

Help @vb2java spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...