do while help please.....

G

Guest

Hello there,


I have two divs named center and right ....


When you hover over the right div i want the center to move to the left as
long as you hover...
on mouse out i want it to stop...


i am pretty sure that its very easy only that i cant do it...


please help me....


Thanx in advance!
 
D

David Mark

Hello there,

I have two divs named center and right ....
Where?


When you hover over the right div i want the center to move to the left as
long as you hover...
on mouse out i want it to stop...

Seems of no practical value. I'd skip it. :)
i am pretty sure that its very easy only that i cant do it...

please help me....

What have you tried....?
 
L

Lasse Reichstein Nielsen

Hello there,


I have two divs named center and right ....


When you hover over the right div i want the center to move to the left as
long as you hover...
on mouse out i want it to stop...

<script type="text/javascript">
var moveId;
function moveLeft() {
var center = document.getElementById("center");
center.style.left = (parseInt(center.style.left, 10) - 1) + "px"
}
</script>
<div id="right" onmouseover="moveId = setInterval(moveLeft,100);"
onmouseout="clearInterval(moveId); moveId = undefined;">
lala
</div>
<div id="center" style="position:absolute;left:400px;">Dada</div>

/L
 
D

David Mark

<script type="text/javascript">
  var moveId;
  function moveLeft() {
    var center = document.getElementById("center");
    center.style.left = (parseInt(center.style.left, 10) - 1) + "px"
parseFloat.

  }
</script>
<div id="right" onmouseover="moveId = setInterval(moveLeft,100);"

window.setInterval(...)

And I'd check to see if an interval is ongoing before setting a new
one, particularly as another element is being moved around between
mouseover and mouseout.
                onmouseout="clearInterval(moveId); moveId = undefined;">

window.clearInterval(...);
moveId = null;

IIRC, intrinsic event handlers were one of your exceptions for using
implied globals. Of course, you should just avoid them altogether.
 
L

Lasse Reichstein Nielsen

David Mark said:
parseFloat.

No, parseInt was deliberate. I don't want fractional pixels.
window.setInterval(...)

No better than just setInterval.
And I'd check to see if an interval is ongoing before setting a new
one, particularly as another element is being moved around between
mouseover and mouseout.

That's a good point. I.e.,

if (typeof moveid != "undefined") { setInterval(moveLeft, 100); }
window.clearInterval(...);
moveId = null;

IIRC, intrinsic event handlers were one of your exceptions for using
implied globals.

True, but "window" and "setInterval" are equivalent on that point.
Using "(function(){return this;})().setInterval" would be safer.

A page author should be able to tell whether it's necessary or not.
Of course, you should just avoid them altogether.

Yes, and the best way to do that is to attach event handlers
programmatically instead of writing them in HTML.

/L
 
D

David Mark

No, parseInt was deliberate. I don't want fractional pixels.

Why not?
No better than just setInterval.

You've got to draw the line somewhere. ;)
That's a good point. I.e.,

 if (typeof moveid != "undefined") { setInterval(moveLeft, 100); }
Yes.




True, but "window" and "setInterval" are equivalent on that point.
Using "(function(){return this;})().setInterval" would be safer.

No, if you want to be totally unambiguous, for a browser:-

var GLOBAL = this;

....

onmouseover="GLOBAL.window.setInterval(...)"
A page author should be able to tell whether it's necessary or not.

Looks at most Web pages, I wonder if the typical page author can tie
his/her shoes. :)
Yes, and the best way to do that is to attach event handlers
programmatically instead of writing them in HTML.

That's beside the point (and not always the best strategy).
 
D

Dmitry A. Soshnikov

[snip]
var GLOBAL = this;

...

onmouseover="GLOBAL.window.setInterval(...)"

You don't exactly whether or not `setInterval' is the property of the
`window' (see in different browsers, I've already showed this in topic
related to `alert' property, here's the same):

alert([
'setInterval' in window,
'setInterval' in this,
Object.prototype.hasOwnProperty.call(this, 'setInterval'),
Object.prototype.hasOwnProperty.call(window, 'setInterval'),

'setTimeout' in window,
'setTimeout' in this,
Object.prototype.hasOwnProperty.call(this, 'setTimeout'),
Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);

The most interesting results for you will be in Chrome and Opera.

So, it's not the pattern that should always be used.

As for me, and that I've already mentioned in similar topic about
`alert', I had a habit to use `window.setTimeout', but have never
wrote `window.alert'. For now I think the best way in code in which
you're sure to write this stuff without any prefixes, simply: `alert',
`setTimeout' and so on.

I won't repeat all that already been said in similar topic about
`alert', but remind, that from the Scope chain point of view -
theoretically in will be the same (searching `window` or
`setTimeout'), but the algorithm of `window.setTimeout' is worse (more
complex) than plain `setTimeout'.

So, why are you after all explanations still continue to propagate the
`window.anyHostObject' instead of plain `anyHostObject'?

/ds
 
D

David Mark

[snip]


var GLOBAL = this;

onmouseover="GLOBAL.window.setInterval(...)"

You don't exactly whether or not `setInterval' is the property of the
`window' (see in different browsers, I've already showed this in topic
related to `alert' property, here's the same):

No, I'm quite sure as we are talking about browsers. That's the
point. If instead, you wish to cover all environments:

onmouseover="(GLOBAL.window || GLOBAL).setInterval(...)"

alert([
  'setInterval' in window,
  'setInterval' in this,
  Object.prototype.hasOwnProperty.call(this, 'setInterval'),
  Object.prototype.hasOwnProperty.call(window, 'setInterval'),

  'setTimeout' in window,
  'setTimeout' in this,
  Object.prototype.hasOwnProperty.call(this, 'setTimeout'),
  Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);

What a complete waste of time. :(
The most interesting results for you will be in Chrome and Opera.

You are clearly confused. Post the results that surprised you.
There's a rational explanation for whatever it is you think you
saw. ;)
 
D

Dmitry A. Soshnikov

var GLOBAL = this;
...
onmouseover="GLOBAL.window.setInterval(...)"
You don't exactly whether or not `setInterval' is the property of the
`window' (see in different browsers, I've already showed this in topic
related to `alert' property, here's the same):

No, I'm quite sure as we are talking about browsers.  That's the
point.  If instead, you wish to cover all environments:

onmouseover="(GLOBAL.window || GLOBAL).setInterval(...)"

The thing is that you can't even say what is "all environments" means
regarding to `setTimeout'.
alert([
  'setInterval' in window,
  'setInterval' in this,
  Object.prototype.hasOwnProperty.call(this, 'setInterval'),
  Object.prototype.hasOwnProperty.call(window, 'setInterval'),
  'setTimeout' in window,
  'setTimeout' in this,
  Object.prototype.hasOwnProperty.call(this, 'setTimeout'),
  Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);

What a complete waste of time.  :(

So, you're not interested in the truth, right? You just want to
protect you point of view, even if it's not the truth? If so, I let to
myself do not waste the time explaining you that. For what, if you
cannot appreciate it calling "complete waste of time"?
You are clearly confused.  Post the results that surprised you.
There's a rational explanation for whatever it is you think you
saw.  ;)

Demagogy.

But keep in mind, when you write on somebody's "setTimeout" something
like "should be window.setTimeout" - you are mistaken and don't
completely understand what you are talking about, especially using
terms such as "Scope chain" and so on.

/ds
 
D

David Mark

On Dec 19, 4:10 pm, "Dmitry A. Soshnikov" <[email protected]>
wrote:
[snip]
var GLOBAL = this;
...
onmouseover="GLOBAL.window.setInterval(...)"
You don't exactly whether or not `setInterval' is the property of the
`window' (see in different browsers, I've already showed this in topic
related to `alert' property, here's the same):
No, I'm quite sure as we are talking about browsers.  That's the
point.  If instead, you wish to cover all environments:
onmouseover="(GLOBAL.window || GLOBAL).setInterval(...)"

The thing is that you can't even say what is "all environments" means
regarding to `setTimeout'.

As in, it won't exist? Yes, eature detection is an important related
topic.
alert([
  'setInterval' in window,
  'setInterval' in this,
  Object.prototype.hasOwnProperty.call(this, 'setInterval'),
  Object.prototype.hasOwnProperty.call(window, 'setInterval'),
  'setTimeout' in window,
  'setTimeout' in this,
  Object.prototype.hasOwnProperty.call(this, 'setTimeout'),
  Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);
What a complete waste of time.  :(

So, you're not interested in the truth, right?

What truth? It's a blob of JS with no asserted results. Even without
results, the tests themselves betray a fundamental misunderstanding
about host objects, which are _implementation dependent_.

And what is the theory you are attempting to prove anyway?
You just want to
protect you point of view, even if it's not the truth?

Unsurprisingly, it has nothing to do with my point of view and
everything to do with the specifications (and lack thereof).
If so, I let to
myself do not waste the time explaining you that.

Explaining what?
For what, if you
cannot appreciate it calling "complete waste of time"?

It was and is. You should appreciate that fact.
Demagogy.

Rubbish.
 
D

Dmitry A. Soshnikov

On Dec 19, 4:10 pm, "Dmitry A. Soshnikov" <[email protected]>
wrote:
[snip]
var GLOBAL = this;
...
onmouseover="GLOBAL.window.setInterval(...)"
You don't exactly whether or not `setInterval' is the property of the
`window' (see in different browsers, I've already showed this in topic
related to `alert' property, here's the same):
No, I'm quite sure as we are talking about browsers.  That's the
point.  If instead, you wish to cover all environments:
onmouseover="(GLOBAL.window || GLOBAL).setInterval(...)"
The thing is that you can't even say what is "all environments" means
regarding to `setTimeout'.

As in, it won't exist?  Yes, eature detection is an important related
topic.




alert([
  'setInterval' in window,
  'setInterval' in this,
  Object.prototype.hasOwnProperty.call(this, 'setInterval'),
  Object.prototype.hasOwnProperty.call(window, 'setInterval'),
  'setTimeout' in window,
  'setTimeout' in this,
  Object.prototype.hasOwnProperty.call(this, 'setTimeout'),
  Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);
What a complete waste of time.  :(
So, you're not interested in the truth, right?

What truth?  It's a blob of JS with no asserted results.  Even without
results, the tests themselves betray a fundamental misunderstanding
about host objects, which are _implementation dependent_.

Demagogy. And, btw, you should understand first what is
"_implementation dependent_" and then talk is such manner, k? ;)
And what is the theory you are attempting to prove anyway?


Unsurprisingly, it has nothing to do with my point of view and
everything to do with the specifications (and lack thereof).

Demagogy.


Explaining what?

Explaining that you're just another troll, which is not interested in
true results and just wanted to talk ;) Is it so hard to understand:
saying "should be window.setTimeout" - you are mistaken. What's wrong
in my phrase? If you would say "would be better window.setTimeout",
maybe it will be better, but nope - 'cause `window.setTimeout' is
worse (has more complex algorithm) than `setTimeout' and in some
implementations it's even not the property of the `window' but
directly the global object.
It was and is.  You should appreciate that fact.

Demagogy.



Rubbish.

Good boy, take a cookie ;) The exit is there. Learn ES and its
implementations deeper too. You are free.

/ds
 
D

David Mark

On Dec 19, 4:39 pm, "Dmitry A. Soshnikov" <[email protected]>
wrote:
On Dec 19, 4:10 pm, "Dmitry A. Soshnikov" <[email protected]>
wrote:
[snip]
var GLOBAL = this;
...
onmouseover="GLOBAL.window.setInterval(...)"
You don't exactly whether or not `setInterval' is the property ofthe
`window' (see in different browsers, I've already showed this in topic
related to `alert' property, here's the same):
No, I'm quite sure as we are talking about browsers.  That's the
point.  If instead, you wish to cover all environments:
onmouseover="(GLOBAL.window || GLOBAL).setInterval(...)"
The thing is that you can't even say what is "all environments" means
regarding to `setTimeout'.
As in, it won't exist?  Yes, eature detection is an important related
topic.
alert([
  'setInterval' in window,
  'setInterval' in this,
  Object.prototype.hasOwnProperty.call(this, 'setInterval'),
  Object.prototype.hasOwnProperty.call(window, 'setInterval'),
  'setTimeout' in window,
  'setTimeout' in this,
  Object.prototype.hasOwnProperty.call(this, 'setTimeout'),
  Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);
What a complete waste of time.  :(
So, you're not interested in the truth, right?
What truth?  It's a blob of JS with no asserted results.  Even without
results, the tests themselves betray a fundamental misunderstanding
about host objects, which are _implementation dependent_.

Demagogy. And, btw, you should understand first what is
"_implementation dependent_" and then talk is such manner, k? ;)
And what is the theory you are attempting to prove anyway?
Unsurprisingly, it has nothing to do with my point of view and
everything to do with the specifications (and lack thereof).

Demagogy.

I take it you like that word. :)
Explaining that you're just another troll,

If "troll" means "anyone who disagrees with you", it's a fair cop.
which is not interested in
true results and just wanted to talk ;)

Dear God, no.
Is it so hard to understand:
saying "should be window.setTimeout" - you are mistaken.

Yes, you are _very_ hard to understand. Clearly English is not your
first language.
What's wrong
in my phrase? If you would say "would be better window.setTimeout",
maybe it will be better, but nope - 'cause `window.setTimeout' is
worse (has more complex algorithm) than `setTimeout' and in some
implementations it's even not the property of the `window' but
directly the global object.

That last sentence is where the wheels come off of your argument
(whatever it is).
Demagogy.

There it is again.
Good boy, take a cookie ;) The exit is there. Learn ES and its
implementations deeper too. You are free.

Pfft. You would do well to pay attention.
 
D

Dmitry A. Soshnikov

[snip]
Yes, you are _very_ hard to understand.  Clearly English is not your
first language.

That's right, English is not my native language, so sorry for the
typos. But you've just shown the main sign that you have nothing to
say else about the theme, so then you should use some demagogy (yep,
again ;)), e.g. talking about bad English.
That last sentence is where the wheels come off of your argument
(whatever it is).

You completely understand what I am about and just uses again demagogy
(yep, again ;)).
There it is again.

Sure again, if you have nothing said about the theme/topic and just
talking about anything but the topic attempting not to fail. That's
called demagogy.
Pfft.  You would do well to pay attention.

Ok, I can't insist and impose the knowledge to you (I said - you are
free and can continue to mistake, that's your choice), so I wish you
good luck ;) Dixi.

/ds
 
D

David Mark

[snip]


Yes, you are _very_ hard to understand.  Clearly English is not your
first language.

That's right, English is not my native language, so sorry for the
typos.

Typos don't bother me.
But you've just shown the main sign that you have nothing to
say else about the theme, so then you should use some demagogy (yep,
again ;)), e.g. talking about bad English.

Uh, no. You opened the door to that. You _are_ hard to understand
because you don't speak my language. It's not a crime, but is
certainly relevant to this misunderstanding.
You completely understand what I am about and just uses again demagogy
(yep, again ;)).

No, I'm trying to teach you something. That's what I get for
trying. :(
Sure again, if you have nothing said about the theme/topic and just
talking about anything but the topic attempting not to fail. That's
called demagogy.

That's called a misinterpretation.
Ok, I can't insist and impose the knowledge to you (I said - you are
free and can continue to mistake, that's your choice), so I wish you
good luck ;) Dixi.

Thanks for that. But luck doesn't really enter into it.
 
G

Guest

Wow...

if i knew id start a fight, id never posted it....
Anyway, i did it, thanx to all of you, but please....keep something in mind,

If someone, like me ask such an 'easy' question, it probablly means that he
is not an expert....


so, keeping answers as easy as possible would really help.... rather than 2
pages of code...

I know, it was meant to help but... as i said before...

Anyway,

Thanx again! Greetings from Greece!
JBK



? "David Mark" <[email protected]> ?????? ??? ??????
[snip]


Yes, you are _very_ hard to understand. Clearly English is not your
first language.

That's right, English is not my native language, so sorry for the
typos.

Typos don't bother me.
But you've just shown the main sign that you have nothing to
say else about the theme, so then you should use some demagogy (yep,
again ;)), e.g. talking about bad English.

Uh, no. You opened the door to that. You _are_ hard to understand
because you don't speak my language. It's not a crime, but is
certainly relevant to this misunderstanding.
You completely understand what I am about and just uses again demagogy
(yep, again ;)).

No, I'm trying to teach you something. That's what I get for
trying. :(
Sure again, if you have nothing said about the theme/topic and just
talking about anything but the topic attempting not to fail. That's
called demagogy.

That's called a misinterpretation.
Ok, I can't insist and impose the knowledge to you (I said - you are
free and can continue to mistake, that's your choice), so I wish you
good luck ;) Dixi.

Thanks for that. But luck doesn't really enter into it.
 
J

JR

You don't exactly whether or not `setInterval' is the property of the
`window' (see in different browsers, I've already showed this in topic
related to `alert' property, here's the same):

alert([
  'setInterval' in window,
  'setInterval' in this,
  Object.prototype.hasOwnProperty.call(this, 'setInterval'),
  Object.prototype.hasOwnProperty.call(window, 'setInterval'),

  'setTimeout' in window,
  'setTimeout' in this,
  Object.prototype.hasOwnProperty.call(this, 'setTimeout'),
  Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);

The most interesting results for you will be in Chrome and Opera.

Even in FF 3.5 the results are different, depending whether I run the
above code in Firebug or in a html page. For instance:

In Firebug: true,false,false,true,true,false,false,true
In a HTML page (with FF): true,true,true,true,true,true,true,true

So, maybe the problem resides in the 'this' keyword used in your
example and in which environment / widget the code is run.

I think the correct test case should be:

<script type="text/javascript">
var GLOBAL = this;
alert([
'setInterval' in window,
'setInterval' in GLOBAL,
Object.prototype.hasOwnProperty.call(GLOBAL, 'setInterval'),
Object.prototype.hasOwnProperty.call(window, 'setInterval'),

'setTimeout' in window,
'setTimeout' in GLOBAL,
Object.prototype.hasOwnProperty.call(GLOBAL, 'setTimeout'),
Object.prototype.hasOwnProperty.call(window, 'setTimeout')
]);
So, it's not the pattern that should always be used.

As for me, and that I've already mentioned in similar topic about
`alert', I had a habit to use `window.setTimeout', but have never
wrote `window.alert'. For now I think the best way in code in which
you're sure to write this stuff without any prefixes, simply: `alert',
`setTimeout' and so on.
I won't repeat all that already been said in similar topic about
`alert', but remind, that from the Scope chain point of view -
theoretically in will be the same (searching `window` or
`setTimeout'), but the algorithm of `window.setTimeout' is worse (more
complex) than plain `setTimeout'.

So, why are you after all explanations still continue to propagate the
`window.anyHostObject' instead of plain `anyHostObject'?

Using 'window.alert' instead of 'alert' would result in a tad faster
code.

Cheers,
JR
 
J

Jorge

Using 'window.alert' instead of 'alert' would result in a tad faster
code.

There's definitely a clear pattern here:

http://jorgechamorro.com/cljs/088/

1.- a= location.href; //implied global
2.- a= window.location.href; //explicit
3.- a= window.window.location.href;
4.- a= window.window.window.location.href;
5.- a= window.window.window.window.location.href;
6.- a= window.window.window.window.window.location.href;

Chrome 4.0.249.43: 1.5 1.2 1.04 0.92 0.82 0.72 (MHz)
Opera 10.10: 766 635 535 460 409 369 (KHz)
Safari 4.0.4: 650 624 617 602 582 578 (KHz)
Opera 9.64: 444 326 267 203 172 157 (KHz)
FireFox 3.6b4: 194 150 116 115 103 95 (KHz)
FireFox 3.5.4: 180 125 90 85 74 66 (KHz)
FireFox 3.0.15: 170 100 90 75 65 57 (KHz)
iCab 3.0.5: 155 133 118 108 101 92 (KHz)
FireFox 2.0.0.20: 110 103 93 83 78 73 (KHz)
Navigator 9.0.0.3: 102 94 83 73 67 63 (KHz)

(Mac OSX 10.6.2)
 
L

Lasse Reichstein Nielsen

JR said:
Using 'window.alert' instead of 'alert' would result in a tad faster
code.

Can you explain why you think that would be the case?
(Because I can't see any reasonable explanation - remember you have to
resolve "window" as well).

/L
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top