473,396 Members | 2,030 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

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 new at this
language, however, I've been programming in C++ for awhile. This is my
code for that part of it. And I call the startAnimation() function
when the button finish is clicked on. Represented like: <INPUT
TYPE="SUBMIT" NAME="SUBMIT" onclick ="startAnimation()" VALUE="Finish">

<STYLE><!--
var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;

function startAnimation(){
anim1 = new animation("paper");
anim1.slideBy(320,2, 99, 50);
}

function animation(id) {
this.element = (NS4) ? document[id] : document.all[id].style;
this.active = 0;
this.timer = null;
this.path = null;
this.num = null;

this.name = id + "Var";
eval(this.name + " = this");

this.animate = animate;
this.step = step;
this.show = show;
this.hide = hide;
this.left = left;
this.top = top;
this.moveTo = moveTo;
this.slideBy = slideBy;
this.slideTo = slideTo;
}

function left() {
return parseInt(this.element.left);
}

function top() {
return parseInt(this.element.top);
}

function left() {
return (NS4) ? this.element.left : this.element.pixelLeft;
}

function top() {
return (NS4) ? this.element.top : this.element.pixelTop;
}

function show() {
this.element.visibility = (NS4) ? "show" : "visible";
}

function hide() {
this.element.visibility = (NS4) ? "hide" : "hidden";
}

function moveTo(x, y) {
this.element.left = x;
this.element.top = y;
}

function slideTo(tx, ty, steps, interval) {
var fx = this.left();
var fy = this.top();
var dx = tx - fx;
var dy = ty - fy;
var sx = dx / steps;
var sy = dy / steps;

var ar = new Array();
for (var i = 0; i < steps; i++) {
fx += sx;
fy += sy;
ar[i] = new pos(fx, fy);
}
this.path = ar;
this.animate(interval);
}

function pos(x, y) {
this.x = Math.round(x);
this.y = Math.round(y);
}

function slideBy(dx, dy, steps, interval) {
var fx = this.left();
var fy = this.top();
var tx = fx + dx;
var ty = fy + dy;
this.slideTo(tx, ty, steps, interval);
}

function animate(interval) {
if (this.active) return;
this.num = 0;
this.active = 1;
this.timer = setInterval(this.name + ".step()", interval);
}

function step() {
this.moveTo(this.path[this.num].x, this.path[this.num].y);
if (this.num >= this.path.length - 1) {
clearInterval(this.timer);
this.active = 0;
if (this.statement)
eval(this.statement);
} else {
this.num++;
}
}

Jul 23 '05 #1
5 2073
Zif
wm*********@noctrl.edu wrote:
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 new at this
language, however, I've been programming in C++ for awhile. This is my
code for that part of it. And I call the startAnimation() function
when the button finish is clicked on. Represented like: <INPUT
TYPE="SUBMIT" NAME="SUBMIT" onclick ="startAnimation()" VALUE="Finish">
I can't agree that such stuff is of any use - I thought that's what
animated cursors were for. Besides, what if the user submits the form
without clicking the submit button? E.g. types some content and
presses enter?

<STYLE><!--
Since what follows appears to be JavaScript, perhaps you'd better put
it in a script element rather than a style element. And while we're at
it, let's include required attributes lest the validator coughs at us -
oh, and remove the HTML comment delimiter, it's very outdated and
potentially harmful:

<script type="text/javascript">
var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;
It's a good idea not to post with tabs, replace them with 2 or 4 spaces
for indents (I've replaced them with one space).

Search for 'feature detection' and 'browser sniffing'. The above is a
totally inadequate test given the purpose which it is put below. It
will also exclude a good percentage (20%? 30%?) of browsers that don't
support document.all or document.layers.

Probably 95% of browsers in use support document.getElementById, it is
a much better strategy to target those browsers by default and then
deal with the exceptions only as required.

There are recently posted examples of how to ensure a suitable outcome
using document.getElementById and still support document.all and
document.layers.

function startAnimation(){
anim1 = new animation("paper");
anim1.slideBy(320,2, 99, 50);
}

function animation(id) {
this.element = (NS4) ? document[id] : document.all[id].style;
The above line will not do what I think you want it to do in any
browser. Guessing at your intention, and if support for
getElementById is used as proposed above, then this becomes:

this.element = document.getElementById(id);
this.active = 0;
this.timer = null;
this.path = null;
this.num = null;

this.name = id + "Var";
eval(this.name + " = this");
Eval is almost never required and is nearly always completely
unnecessary. I can't see that it does anything here.

this.name = id + "Var";

[...]

function left() {
return (NS4) ? this.element.left : this.element.pixelLeft;
}

function top() {
return (NS4) ? this.element.top : this.element.pixelTop;
}


Accessing the position of elements in a page varies from browser to
browser. Browse around quirksmode:

<URL:http://www.quirksmode.org/js/cross_dhtml.html>

The link is to a page on DHTML, but much of what it does is applicable
to your stuff here.

This highlights that the browser test above infers support for many
features based on testing just one method of one object - a very
unreliable strategy.

[...]

What do you expect will make the animation stop?
--
Zif
Jul 23 '05 #2
Jc
wm*********@noctrl.edu wrote:
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.


Perhaps toggling the display of an image element pointing to an
animated GIF representing your animation would work better.

Jul 23 '05 #3

"Zif" <zi***@hotmail.com> wrote in message
news:8J*****************@news.optus.net.au...
wm*********@noctrl.edu wrote:
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 new at this
language, however, I've been programming in C++ for awhile. This is my
code for that part of it. And I call the startAnimation() function
when the button finish is clicked on. Represented like: <INPUT
TYPE="SUBMIT" NAME="SUBMIT" onclick ="startAnimation()" VALUE="Finish">
I can't agree that such stuff is of any use - I thought that's what
animated cursors were for. Besides, what if the user submits the form
without clicking the submit button? E.g. types some content and
presses enter?

<STYLE><!--


Since what follows appears to be JavaScript, perhaps you'd better put
it in a script element rather than a style element. And while we're at
it, let's include required attributes lest the validator coughs at us -
oh, and remove the HTML comment delimiter, it's very outdated and
potentially harmful:

.... snipped ....
--
Zif


I'm new to HTML, and so am curious as to why you admonish removing the HTML
comment delimiter. Is there a preferred way to put in a comment? Thanks.
Also, for maximum browser compatibility, should I use jscript or javascript?
Thanks again. -Fred
Jul 23 '05 #4
Zif
Fred Exley wrote:
"Zif" <zi***@hotmail.com> wrote in message
news:8J*****************@news.optus.net.au...
wm*********@noctrl.edu wrote:
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 new at this
language, however, I've been programming in C++ for awhile. This is my
code for that part of it. And I call the startAnimation() function
when the button finish is clicked on. Represented like: <INPUT
TYPE="SUBMIT" NAME="SUBMIT" onclick ="startAnimation()" VALUE="Finish">
I can't agree that such stuff is of any use - I thought that's what
animated cursors were for. Besides, what if the user submits the form
without clicking the submit button? E.g. types some content and
presses enter?

<STYLE><!--


Since what follows appears to be JavaScript, perhaps you'd better put
it in a script element rather than a style element. And while we're at
it, let's include required attributes lest the validator coughs at us -
oh, and remove the HTML comment delimiter, it's very outdated and
potentially harmful:


... snipped ....
--
Zif

I'm new to HTML, and so am curious as to why you admonish removing the HTML
comment delimiter. Is there a preferred way to put in a comment? Thanks.


Admonish? I'd have said 'advise' removal. :-)

There is no need to try to hide scripts with HTML comments at all. The
'script' tag was introduced with HTML 3.2 (about 1996/7 I think). Any
browser released after that should know not to render the content, even
if they don't understand it.

'JavaScript' was introduced by Netscape Communications in Navigator 2
(about 1995), Microsoft introduced support in IE 3, so any browser less
than say 9 years old has no excuse for not knowing what to do with
script elements.

Most advice is that scripts should be in an external file anyway,
leaving the script element empty and removing any last vestige of a
requirement to 'hide' the script:

<script type="text/javascript" src="a_script_file.js"></script>

Though for posting working examples to this newsgroup it's highly
desirable to include the script contents in the HTML.
Also, for maximum browser compatibility, should I use jscript or javascript?
Jscript and JavaScript are both implementations of ECMAScript Language
(ECMA-262). Jscript is Microsoft's name for their implementation,
everyone else calls their's JavaScript.

Substituting 'jscript' for 'javascript' in the type attribute of the
script tag will prevent your script from working in most browsers other
than IE. IE is happy to work with JavaScript, so use 'javascript'.
Thanks again. -Fred


You're welcome. :-)
--
Zif
Jul 23 '05 #5
>> ... snipped ....
--
Zif

I'm new to HTML, and so am curious as to why you admonish removing the
HTML comment delimiter. Is there a preferred way to put in a comment?
Thanks.


Admonish? I'd have said 'advise' removal. :-)

There is no need to try to hide scripts with HTML comments at all. The
'script' tag was introduced with HTML 3.2 (about 1996/7 I think). Any
browser released after that should know not to render the content, even
if they don't understand it.

'JavaScript' was introduced by Netscape Communications in Navigator 2
(about 1995), Microsoft introduced support in IE 3, so any browser less
than say 9 years old has no excuse for not knowing what to do with
script elements.

Most advice is that scripts should be in an external file anyway,
leaving the script element empty and removing any last vestige of a
requirement to 'hide' the script:

<script type="text/javascript" src="a_script_file.js"></script>

Though for posting working examples to this newsgroup it's highly
desirable to include the script contents in the HTML.
Also, for maximum browser compatibility, should I use jscript or
javascript?


Jscript and JavaScript are both implementations of ECMAScript Language
(ECMA-262). Jscript is Microsoft's name for their implementation,
everyone else calls their's JavaScript.

Substituting 'jscript' for 'javascript' in the type attribute of the
script tag will prevent your script from working in most browsers other
than IE. IE is happy to work with JavaScript, so use 'javascript'.
Thanks again. -Fred


You're welcome. :-)
--
Zif

Thanks very much. I just removed the comments wrapped around scripts, and
hey, they still work! :) And I'll go with JavaScript too -why chance any
Microsoft surprises down the road, come to think of it... -Fred
Jul 23 '05 #6

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....
3
by: Mike Zimmer | last post by:
I have a link and a gif (animation) on my site. If the Link opens für example a popup the animation stands still. Who can help me? Thx and big greetings - Mike sorry for my English :)
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...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.