473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JavaScript Animation Issues...

Hello again.

Lol...Now that I finally got that part out of the way earlier. Here's the
real issue.

I'm suppose to create text that scrolls when you click start and stops when
you click stop.
The thought was that I could create text and insert it into a div and just
get the left property of the div and increment that over time....Not sure if
I'm right. But now nothing appears again...

Here's my attempt:

<html><head><title>Problem6</title>
<style type="text/css">

#space{position:absolute; left:10px; top:20px; width:200px; height:50px;
border:1px solid black;}

#mybuttons{position:absolute; left:10px; top:75px;}

</style>
<script type="text/javascript">

origin_x = my_div.style.left;
target_x = 200px;
x_rate = 25; //how fast it's moving...
x_duration = 5;// how long it should take to reach it's destination...
x_increment = (target_x - origin_x / x_rate * x_duration);
x_scroll = origin_x;
var the_timeout;

function inputText(){
var my_message="I love football";
var my_div=document.getElementById("text");
my_div.innerHTML=my_message;
}
function attachHandlers(){

var first_button=document.getElementById("start");
var second_button=document.getElementById("stop");
first_button.onclick=startScroll();
second_button.onclick=stopScroll();

}
function startScroll(){

x_scroll += x_increment;

if ((target_x origin_x && x_scroll target_x))
{
x_scroll = -target_x;
}

else
{
var the_timeout= setTimeout("startScroll()", 500/x_rate);
}

var text_div = document.getElementById("text");
text_div.style.left=Math.round(x_scroll)+"px";

}

function stopScroll(){

clearTimeout(the_timeout);

}

</script>
</head>
<body onLoad="inputText()";"attachHandlers()">
<div id="space">
<div id="text"></div>
</div>
<div id="mybuttons">
<input type="button" value="startscroll" id="start">
<input type="button" value="stopscroll" id="stop">
</div>

</body>
</html>

Please let me know what you think...

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200809/1

Sep 28 '08 #1
1 1422
On 2008-09-28 05:52, ChuckB via WebmasterKB.com wrote:
Lol...Now that I finally got that part out of the way earlier. Here's the
real issue.
Let's take this one step at a time. You have a number of errors in your
script, and I wonder if you can even see them? When you're writing a
script, you want to turn on all the debugging methods you've got (like
enabling script debugging in Internet Explorer, for example).

Here's a suggestion that will make your life a lot easier, and you won't
have to ask in this group for every single problem: Use Firefox for
development, and install the Firebug add-on. This will give you most of
the information you need to debug your script. Internet Explorer is
completely useless here.
<script type="text/javascript">

origin_x = my_div.style.left;
1) When you define a new variable, always use the "var" keyword.
2) my_div is not defined (Firebug would have told you that)
target_x = 200px;
200px is a string, and must be quoted: "200px".
The way you put it, it's a syntax error.
(Firebug would have caught that too)
x_rate = 25; //how fast it's moving...
By convention, constants are usually written in ALL_UPPERCASE. It makes
them easier to spot in complex scripts. That's not an error, just a
suggestion.
x_duration = 5;// how long it should take to reach it's destination...
x_increment = (target_x - origin_x / x_rate * x_duration);
The parentheses are not necessary here (but not an error either).
first_button.onclick=startScroll();
This doesn't do what you expect. It calls startScroll right away, and
assigns startScroll's return value to first_button.onclick. What you
want to do is

first_button.onclick = startScroll; // without the ()
<body onLoad="inputText()";"attachHandlers()">
That's another syntax error. The attribute value of onload is delimited
by the quotes, but you're inserting more quotes in the middle (why?).
This should be

<body onload="inputText(); attachHandlers()">

You could have caught that error by validating your HTML document (which
you should *always* do before you even begin looking for JavaScript
errors). Use this:

http://validator.w3.org/
Please let me know what you think...
I'm not saying the script is going to work now, but you've got a few
pointers. Please, do install Firebug. It'll help you a lot more, and a
lot faster than this group possibly could.

Good luck!
- Conrad
Sep 28 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Reid Goldsborough | last post by:
Hi. I'm a JavaScript neophyte. I'm trying to create a JPEG animation, with one coin (tet) morphing into another. The code doesn't work. Anybody feel like taking a shot at correcting me? It's short....
2
by: billrdio | last post by:
I am trying to make a JavaScript animation of real-time images - i.e. images that will periodically change on the server. The problem I am having is that the JavaScript animation I have created is...
5
by: wmschneider | last post by:
I am trying to make a progress animation so that the user knows that there files are correctly being checked in. Trying to animate papers moving from the computer to the server pics. I'm brand...
1
by: Scott | last post by:
I have an asp.net page that performs a function for a user that can take up to 30 seconds. So, I have a javascript function that shows an animation to let the user know something is going on. I...
2
by: Chris | last post by:
Hi, I have a Javascript function that loads a page with a progress bar for long process. The progress bar is a gif animation and for some reason it the animation is stuck when the function is...
1
by: Pete Smith | last post by:
I am making the animated text inside the table cell data. The animation is done using Javascript. Here is the code looks like.. <table><tr><td><script>Java Script code which does animation of...
3
by: | last post by:
Can someone point me to some good info on how to do somoe simple animation on a form. Specifically, I want to have some tiles that when they are clicked, they flip over in place and reveal a...
4
by: lilOlMe | last post by:
Hi there! I've run into a bit of a problem wherein a <div> containing an error message is made invisible by an animation. I've tried everything to make this <div> reappear on a button click...
5
Frinavale
by: Frinavale | last post by:
I have a slight problem with a Tab Control that I've developed for an application. Once sent to the browser it runs via JavaScript. The JavaScript is dynamically generated by my .NET code. ...
5
by: voidinutah | last post by:
Hello, I'm new to .NET and was trying to find a solution for having a button control do a post back then execute a javascript function. When the button is clicked a post back occurs to save...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.