Making a group of objects up and down

E

Evertjan.

Jonathan Fine wrote on 06 sep 2009 in comp.lang.javascript:
Was : Re: Making a group of objects up and down

Names removed:

Attributions reinstated, because that is according tho Netiquette
Unkind personal remarks are off-topic

This is not unkind,
and even if it were, that does not make it off topic.

Usenet is not about being kind.
The OP did not even try to use javascript,
so he could not be up to the job.
 
R

RobG

Hi,

I have basic knowledge on Javascript, but am not able to code for the
project contained in the following web page:

http://www.pinyinology.com/myFile/moving2a.html

You help is greatly appreciated.

fulio pen

How about using an animated gif? When the stop button is clicked,
replace the animated images with static ones. Can be done with CSS and
class attribute, change the CSS rule for the class to start and stop
the image moving.

I expect most users will like to stop it as it will be a bit annoying.
 
J

John G Harris

Hello Fulio

I had a look at the page, but did not see any JavaScript. Perhaps
you'd like to tell us more about the difficulties you have in writing
the JavaScript.

What a useless reply.

The displayed text says what's wanted. He needs a hint on where to
start.

John
 
S

SAM

Le 9/7/09 12:43 AM, RobG a écrit :
How about using an animated gif? When the stop button is clicked,
replace the animated images with static ones. Can be done with CSS and
class attribute, change the CSS rule for the class to start and stop
the image moving.

I expect most users will like to stop it as it will be a bit annoying.

I don't know about animated gifs in background (css) if they are
animated under IE (tested long time ago they were'nt) but normally with
Firefox you have the Escape key to stop those flashy gifs.
I'm now waiting for a short-cut to stop too the flashy flash animations.


CSS :
=====
..arrow { padding: 8px 0 0 0;
text-align: center; color: red; font-size: 150% }
..up { padding: 0 0 8px 0 }

JS :
====
var anim = false;
function animate() {
var a, n, t;
a = document.getElementById('arrows').getElementsByTagName('TD');
n = a.length;
if(n) {
while(n--) {
t = a[n].className;
a[n].className = t.match('up')? 'arrow' : 'arrow up';
}
anim = setTimeout('animate()', 200);
}
}

HTML
====
<table>
<tr id="arrows">
<td>&nbsp;</td>
<td colspan="2" class="arrow">?</td>
<td>&nbsp;</td>
</tr>
<td id="letters">
<td>g</td>
<td>u(</td>
<td>s</td>
<td>h</td>
</tr>
</table>
<p><button onclick="animate()">action</button>
<p><button onclick="clearTimeout(anim);">stop</button>
 
A

abozhilov

t = a[n].className;

Working with `className` property isn't very useful. When you getting
`className` property, browser will trim whitespace from begining and
end of string. This is slow operation.
t.match('up')

That is unusual. This is equivalent:
/up/.exec(t);

15.5.4.10 String.prototype.match (regexp)
If regexp is not an object whose [[Class]] property is "RegExp", it is
replaced with the result of the expression new
RegExp(regexp). Let string denote the result of converting the this
value to a string. Then do one of the following:
If regexp.global is false: Return the result obtained by invoking
RegExp.prototype.exec (see section
15.10.6.2) on regexp with string as parameter.
setTimeout('animate()', 200);

This case is interesting. Why you use string value for first argument
of setTimeout?
This will be evaluate, before animate executing.

I have question about this? Why this isn't deprecated? This is dirty.
Why setTimeout and setInteval don't check first argument to [[Call]]
internal method?
 
T

Thomas 'PointedEars' Lahn

abozhilov said:
SAM said:
t = a[n].className;

Working with `className` property isn't very useful. When you getting
`className` property, browser will trim whitespace from begining and
end of string. This is slow operation.

If it is done, which I doubt, it is faster than anything else because it is
a DOM-internal getter.
This case is interesting. Why you use string value for first argument
of setTimeout?

Good question.
This will be evaluate, before animate executing.

So what?
I have question about this? Why this isn't deprecated?
Beackwards-compatibility.

This is dirty.

That is a useless statement.
Why setTimeout and setInteval don't check first argument to [[Call]]
internal method?

Because that would break backwards-compatibility. Because those are not
language features. Because ...


PointedEars
 
S

SAM

Le 9/7/09 10:21 PM, abozhilov a écrit :
t = a[n].className;

Working with `className` property isn't very useful. When you getting
`className` property, browser will trim whitespace from begining and
end of string. This is slow operation.

Maybe, I don't know.
(and what are those whitespaces edging ?)
(who play to loose all his whitespaces anywhere ?)

And You propose ?
That is unusual. This is equivalent:
/up/.exec(t);

Probably.
I had too : t.indexOf('up')>0
We could also have : t=='arrow'
15.5.4.10 String.prototype.match (regexp)
If regexp is not an object whose [[Class]] property is "RegExp", it is
replaced with the result of the expression new
RegExp(regexp). Let string denote the result of converting the this
value to a string. Then do one of the following:
If regexp.global is false: Return the result obtained by invoking
RegExp.prototype.exec (see section
15.10.6.2) on regexp with string as parameter.

When Refs will be in french perhaps will I begin to understand them.
Would that mean it would be better with :
t.match(/(up)/) ?
OK, why not.
This case is interesting. Why you use string value for first argument
of setTimeout?

Because one of my IE does'nt understand :
setTimeout(animate, 200);
This will be evaluate, before animate executing.

???
Do you think that :
setTimeout(function(){animate();},200)
will need no evaluation ?

I have question about this? Why this isn't deprecated? This is dirty.
Why setTimeout and setInteval don't check first argument to [[Call]]
internal method?

Witch "internal" method ? from what ?

Why Microsoft's teams didn't think to it before ?
 
R

RobG

Le 9/7/09 12:43 AM, RobG a écrit :






I don't know about animated gifs in background (css) if they are

They don't need to be backgorund gifs. Consider each animated gif
positioned over the top of a static gif, then modify their CSS rules
to toggle between showing one set or the other.
 
S

SAM

Le 9/8/09 12:03 AM, RobG a écrit :
They don't need to be backgorund gifs. Consider each animated gif
positioned over the top of a static gif, then modify their CSS rules
to toggle between showing one set or the other.

It's so easily made in background that I did'nt see this way of doing.

Thinking to it ... finaly it appears as not so difficult with
appendChild or insertBefore
(no really needing of changing class)
 
R

RobG

Le 9/8/09 12:03 AM, RobG a écrit :





It's so easily made in background that I did'nt see this way of doing.

Thinking to it ... finaly it appears as not so difficult with
appendChild or insertBefore
(no really needing of changing class)

I didn't suggest changing the class (though a class might be used to
create a group of related elements), I suggested changing the CSS
rules. Then all related elements are changed at once - no looping over
elements to add and remove classes or child nodes and therefore very
much faster.
 
T

The Natural Philosopher

Jonathan said:
My aim is not to complain about other posts but to improve the general
level of communication on this group.

Got the cross on your breastplate and a shiny white horse?

Really, this is 2009, and usenet 'rules' are unenforceable.


The only pragmatic approach is, don't respond to what you don't like,
and if it repeatedly comes from a single source, filter that source.
(I know that some may consider my comment to be a complaint, and
therefore against the advice of the FAQ.)

Frankly my dear, I don't give a dam, not for the rudeness of which you
speak, your complaint about it, or Usenet rules and FAQ's.

Having runs several small businesses, I learnt that there is the Law,
there is common sense, there are standard practices and recommendations,
and there is *that which is effective*. They are seldom the same thing.
 
O

optimistx

Having runs several small businesses, I learnt that there is the Law,
there is common sense, there are standard practices and
recommendations, and there is *that which is effective*. They are
seldom the same thing.

There was a guy who told the he is really an expert to succeed in marriages,
and is happy to give his advice to everyone wanting to have a happy
marriage.

Then there was an innocent question:

"How is your wife"

"She is very happy, and also everyone of my earlier five wives"

Politeness and empathy are not enforceable. But trying to be kind makes
oneself to feel happier, before long. And kindness is contagious.

I think everyone of the regulars are searching some satisfaction for oneself
here, not writing as a duty or obligation.

But the longer the regular has learnt things here, the less the newbies can
give him interesting problems to solve. The disappointment might become
anger, impoliteness, unkindness.

'Where are the good old days when I learnt interesting things every day? Now
there are only stupid questions, repetition of the old ones. Go away
everyone who is not more skilful than I am!'

If one has learn a lot, writing a book about javascript might give
satisfaction for the author and the readers. 'Yucca' Korpela did so: his
book about CSS is enjoyable and accurate, reasonably friendly tone.
Obviously someone with good human relations understanding has been involved.

Is the writing in the internet such also? You might remember, or check
yourself, if not.
 
T

The Natural Philosopher

optimistx said:
There was a guy who told the he is really an expert to succeed in
marriages, and is happy to give his advice to everyone wanting to have a
happy marriage.

Then there was an innocent question:

"How is your wife"

"She is very happy, and also everyone of my earlier five wives"

Politeness and empathy are not enforceable. But trying to be kind makes
oneself to feel happier, before long. And kindness is contagious.

I think everyone of the regulars are searching some satisfaction for
oneself here, not writing as a duty or obligation.

But the longer the regular has learnt things here, the less the newbies
can give him interesting problems to solve. The disappointment might
become anger, impoliteness, unkindness.

'Where are the good old days when I learnt interesting things every day?
Now there are only stupid questions, repetition of the old ones. Go away
everyone who is not more skilful than I am!'

Well I got to that stage in one online forum I frequent.

Now I don't bother to reply at all. Someone else can.

I only answer stuff where I have a particular interest, gap in my own
knowledge, or feel a witty remark coming on.

I think te same is true of the better posters here.

There are a few court holders in every group - those who spend their
time answering everybody, usually rudely, as if they had some kind of
real status to act as arbiters ..'empty vessels sound loudests' ..then
there are the few who pop up and do answer, clearly, succinctly and
simply. The valuable ones.

Its easy to distinguish between 'this aint a javsacript question: take
it to HTML, stoopid noob' and 'this actually is a CSS issue, but since
you are here and I have the time, try this..'


I suspect the former response comes from those who *have read the
manual* and know the language really well or think they do..and those
who have *used it to solve real life problems* and understand that its
not always obvious where a solution lies. I.e. the perennial problem of
'its in the man pages' and 'but WHICH man page is it in' ??



If one has learn a lot, writing a book about javascript might give
satisfaction for the author and the readers. 'Yucca' Korpela did so: his
book about CSS is enjoyable and accurate, reasonably friendly tone.
Obviously someone with good human relations understanding has been
involved.

Is the writing in the internet such also? You might remember, or check
yourself, if not.


Shrug. I have written a lot of posts, some right, a few wrong, some
cryptic, many receiving praise for lucidity. Writing is a skill, as is
understanding from someone else's perspective WHY they find a particular
point difficult..

All I can say is thank GOD for google and the internet. Problems that
used to take weeks are generally fixed with an hour of googling..

If they are not, they possibly are NOT fixable.
 
S

SAM

Le 9/8/09 4:32 AM, RobG a écrit :
I didn't suggest changing the class (though a class might be used to
create a group of related elements), I suggested changing the CSS
rules.

Yes, that's right.
Then all related elements are changed at once - no looping over
elements to add and remove classes or child nodes and therefore very
much faster.

Except I don't know how to do it ;-)
(manipulating styles-sheets rules with all particularities of browsers
ask much more lines than to launch an insertBefore, I think)
 
A

abozhilov


This provide you, easy way to errors. Again my dummy words... I would
to say.

setTimeout('animate()', 200);
Looks like: eval('animate()');

This string 'animate()', will be parse and after that will be
executing. This will be start to parsing after 200ms. For my, this is
very bad. If you have syntax error? How to catch error in this case?
This error not terminate current thread. But is error.

Do you have a time for little explained, how it works setTimeout? I
thing setTimeout create new thread and execute code in that thread. I
will be very grateful to anybody if explain or share material for
setTimeout.

I have and another question:
Why 'animate()' isn't parse when i call setTimeout?
Beackwards-compatibility.

Here you are right, but if today i need from setTimeout, i never use
string value for first argument of setTimeout.

Thanks for answers ;~)
 
S

SAM

Le 9/8/09 6:56 PM, abozhilov a écrit :
setTimeout('animate()', 200);
Looks like: eval('animate()');

Ha! Tiens ? oui! It does.
This string 'animate()', will be parse and after that will be
executing. This will be start to parsing after 200ms. For my, this is
very bad. If you have syntax error? How to catch error in this case?

In the Firefox's Consol of errors ?
With Fire Bug (extension for Fx) ?
This error not terminate current thread. But is error.

Why do you want absolutely make errors ?
Do you have a time for little explained, how it works setTimeout? I
thing setTimeout create new thread and execute code in that thread. I

From what I understood of JavaScript : it is a single thread language.
If what is runing in the function in 1st argument probably that will be
seen as a muti-thread
In fact no :

function f() {
if(confirm('choice a button below'))
alert('button [OK]');
else alert('button [Cancel]');
}
setTimeout(function(){alert('a little pause');},510);
setTimeout('f()',500);

I have and another question:
Why 'animate()' isn't parse when i call setTimeout?

? not understood what parsing could be (here).
animate() is known by the browser (parser?) it had already read it
and the function is in memory, no?
Not even an variable that changes.
Here you are right, but if today i need from setTimeout, i never use
string value for first argument of setTimeout.

I do not see really the difference doing :
setTimeout(function(){animate();},200);
Would that have a bit of chance to answer at errors catching ?
 
A

abozhilov

Le 9/8/09 6:56 PM, abozhilov a écrit :

In the Firefox's Consol of errors ?
With Fire Bug (extension for Fx) ?

I want runtime catch this error. I don't want to flood error console
on user browser.

 From what I understood of JavaScript : it is a single thread language.
If what is runing in the function in 1st argument probably that will be
seen as a muti-thread
In fact no :

confirm and alert ares modal window. Modal window of browser.
http://en.wikipedia.org/wiki/Modal_window

confirm and alert sleeping the all thread of browser until be closed.
Test with another code. Call confirm before all page been rendered
from browser and see what's happening.
? not understood what parsing could be (here).
animate() is known by the browser (parser?) it had already read it
and the function is in memory, no?
Not even an variable that changes.

If setTimeout use internaly Global Object eval. We have next step:
ECMA 3.
15.1.2.1 eval (x)
When the eval function is called with one argument x, the following
steps are taken:
1. If x is not a string value, return x.
2. Parse x as a Program. If the parse fails, throw a SyntaxError
exception (but see also section 16).
3. Evaluate the program from step 2.
4. If Result(3).type is normal and its completion value is a value V,
then return the value V.
5. If Result(3).type is normal and its completion value is empty, then
return the value undefined.
6. Result(3).type must be throw. Throw Result(3).value as an
exception.

Look point 2. For that parsing i talk about.
I do not see really the difference doing :
   setTimeout(function(){animate();},200);

The difference in this case is.
First argument of setTimeout is reference.
You create anonymous function. Anonymous function in this case, not
assigned to anything. After calling this function will be marked to
GC.
That anonymous function when you initialize will be return reference.
Anonymous function will be referred to `object` who have [[Call]]
internal method. In this case we don't need to parsing code. After
check for [[Call]] method will be execute this anonymous function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top