|
|
|
date: Tue, 16 Oct 2007 21:13:13 -0400,
group: microsoft.public.inetsdk.programming.scripting.jscript
back
Re: Why won't the following work in FireFox?
On Oct 17, 11:30 pm, dNagel wrote:
> >> e = e || window.event;
>
> > You don't need this line. Your inline handler passed the event
> > object.
>
> You do need it... event is not valid in firefox, so it will pass
Wrong.
> undefined instead of what you think
If that were true, your code would try to use window.event, which
certainly isn't valid in FF.
> should be the event object. FFox always passes the event object into
> the into an event procedure.
You need to re-read your code.
> If you do not use my code exactly as I have written it, it will fail. I
> promise you that.
You can promise anything you want. You are still incorrect.
>
> >> var el = e.target || e.srcElement;
>
> > You wouldn't need this line if you passed "this" as a second
> > parameter.
>
> Why pass it as a parameter when the event object already has it as a
> property.
It is simpler to do it that way. The resulting code is smaller as
well.
>> draggable=1;
> >> el.style.position='absolute';
> >> el.style.left=( e.x || e.clientX )-25+'px';
>
> > As I mentioned in my missing post, you shouldn't use the x/y pair.
> > Use pageX/Y if defined, then try clientX/Y and then give up as x/y and
> > layerX/layerY are unpredictable. This works reliably on virtually
> > every modern browser (and many older ones too.)
>
> sounds good to me.
>
> > There are a few problems with the above line of code. For one, your
> > test is off. If e.x is 0 and e.clientX is undefined, you will end up
> > with NaNpx. Same if e.x and e.clientX are both undefined. Then there
> > is the scroll position of the document to deal with (clientX/Y returns
> > coordinates relative to the viewport.)
>
> > I don't see the significance of 25 either, but that is from the
> > original.
>
> agreed, but what it does is "position the cursor" a bit inside of the
> object so that accelerated mouse
> movement does not allow the mouse to escape the "capture".
That is a pretty unreliable approach and will make the element jump
every time you drag it. Just attach the onmousemove and onmouseup
handlers to the document.
date: Thu, 18 Oct 2007 01:39:42 -0700
author: David Mark
Re: Why won't the following work in FireFox?
On Oct 18, 7:24 am, dNagel wrote:
> David Mark wrote:
> >> You do need it... event is not valid in firefox, so it will pass
>
> > Wrong.
>
> Well, if I;m so wrong, can you please explain to me (in a full example)
As you noted below, there is no if about it.
> how you would implement your suggestions?
My drag and drop code looks very different from this. There's no
quick fix.
>
> This is as close as I could get to implementing your suggestions.
> Removing the -25px makes the drag impossible
I don't see why that would make any difference. Regardless, you
should store the mouse coordinates and position of the element on
mousedown and then calculate and apply the difference on each
mousemove event.
> with a highly accelerated mouse. Theres no way to pass ( this ) into a
> document event procedure.
That's not quite true.
document.onclick = function(e) { alert(this); };
Of course, "this" is the document object in this case.
Here is a hint. You have a reference to the element in question in
the onmousedown handler. And you don't need to assign the document
handlers until this point. So you can use a closure to keep the
element reference in scope. Alternatively, just store the reference
to the element in a global variable.
date: Thu, 18 Oct 2007 08:39:53 -0700
author: David Mark
|
|