Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   <!DOCTYPE> breaking a script? (http://www.velocityreviews.com/forums/t879909-doctype-breaking-a-script.html)

Matthew Schubert 10-04-2004 03:11 PM

<!DOCTYPE> breaking a script?
 
I have reason for an element on a page to be static, like the CSS property
"position: fixed" defines.

Obviously, this CSS property doesn't work in IE :-/

I have looked around at alternatives, and found one that suits my needs, an
active Javascript that changes the position of the element when the page is
scrolled.

A simple test implementation of the script can be seen at
http://evil.mooo.com/test.html. It works perfectly.

When I add a <!DOCTYPE> declaration to the top of the page, so it conforms
with W3C's standards, the script breaks, and I get this
http://evil.mooo.com/test2.html.

What is happening? Any ideas?



ZER0 10-04-2004 03:18 PM

Re: <!DOCTYPE> breaking a script?
 
On Mon, 04 Oct 2004 15:11:13 GMT, Matthew Schubert wrote:

> I have reason for an element on a page to be static, like the CSS property
> "position: fixed" defines.


> Obviously, this CSS property doesn't work in IE :-/


Exactly.

> I have looked around at alternatives, and found one that suits my needs, an
> active Javascript that changes the position of the element when the page is
> scrolled.


This is old school method. Use expression instead (IE5+)

> When I add a <!DOCTYPE> declaration to the top of the page, so it conforms
> with W3C's standards, the script breaks, and I get this
> http://evil.mooo.com/test2.html.


> What is happening? Any ideas?


Replacing document.body with document.documentElement.

You can check the document.compatMode for choose body or documentElement.



--
ZER0://coder.gfxer.web-designer/

~ Come devo regolare la stampante laser per stordire?
(How do I set a laser printer to stun?)

on air ~ "Yellowcard - Breathing"

Matthew Schubert 10-04-2004 03:28 PM

Re: <!DOCTYPE> breaking a script?
 
> This is old school method. Use expression instead (IE5+)

Eh?

> Replacing document.body with document.documentElement.


Tried. Failed (At least in Firefox).



Michael Winter 10-04-2004 03:29 PM

Re: <!DOCTYPE> breaking a script?
 
On Mon, 04 Oct 2004 15:11:13 GMT, Matthew Schubert
<sales@addstylecleaning.com> wrote:

> I have reason for an element on a page to be static, like the CSS
> property "position: fixed" defines.
>
> Obviously, this CSS property doesn't work in IE :-/


Someone asked for something similar recently in this thread:

<URL:http://groups.google.com/groups?threadm=1319c3c8.0409281107.1b34b642%40post ing.google.com>

Though in my final solution, the fixed content was centred. It's easy
enough to adjust, though. Ask if you need help.

> I have looked around at alternatives, and found one that suits my needs,
> an active Javascript that changes the position of the element when the
> page is scrolled.


I must say, it's a horrible implementation. Browser detection should
always be avoided with feature detection used in its place. In this case,
I used Microsoft's conditional comments, the contents of which change the
position property to absolute and add a script which moves the box when
the page is scrolled.

> A simple test implementation of the script can be seen at
> http://evil.mooo.com/test.html. It works perfectly.
>
> When I add a <!DOCTYPE> declaration to the top of the page, so it
> conforms with W3C's standards, the script breaks, and I get this
> http://evil.mooo.com/test2.html.
>
> What is happening? Any ideas?


The problem you're seeing is that when a DOCTYPE is specified, IE, like
most browsers, switches into strict mode. When IE does this, it uses
document.documentElement, not document.body, to hold the clientWidth, and
similar, properties. The code I've presented adapts as necessary[1].

Hope that helps,
Mike


[1] Many thanks to Richard Cornford for the concept, or at least an
implementation of it.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

ZER0 10-04-2004 03:37 PM

Re: <!DOCTYPE> breaking a script?
 
On Mon, 04 Oct 2004 15:28:20 GMT, Matthew Schubert wrote:

>> This is old school method. Use expression instead (IE5+)


> Eh?


http://msdn.microsoft.com/workshop/a...iew/recalc.asp

Of course, expressions are not a w3c standard. But fix a lot of stuff in
IE.
You can use position:fixed for the browsers w3c compliant; and expression
for emulate it in IE.

>> Replacing document.body with document.documentElement.


> Tried. Failed (At least in Firefox).


I'm talking about IE. In IE it works. In Firefox it doesn't works 'cause
you missed the "px" suffix in your measures.

--
ZER0://coder.gfxer.web-designer/

~ Io non soffro di pazzia, ne godo ogni minuto.
(I don't suffer from insanity, I enjoy every minute of it)

on air ~ "Donots - Saccharine Smiles"

Matthew Schubert 10-04-2004 03:50 PM

Re: <!DOCTYPE> breaking a script?
 
Why is the second <script> outside of the IE conditional comments?

Is it not required only by IE in this case? (Remember I do not need the
button to make the DIV visible).

It is a nice implementation. One thing though. I do not like the way it
"jerks" when scrolling. The original script I posted smoothly scrolled the
DIV...

Also, I tried replacing document.body with document.documentElement, and it
works perfectly in IE, but not in Firefox :-/

I think I will use your script, with a little modification :-) Thanks a
bunch.



Michael Winter 10-04-2004 04:14 PM

Re: <!DOCTYPE> breaking a script?
 
On Mon, 04 Oct 2004 15:50:27 GMT, Matthew Schubert
<sales@addstylecleaning.com> wrote:

> Why is the second <script> outside of the IE conditional comments?
>
> Is it not required only by IE in this case? (Remember I do not need the
> button to make the DIV visible).


The code there, part of a larger collection, is used in both the IE code
and the showWait function, used to make the DIV appear.

> It is a nice implementation. One thing though. I do not like the way it
> "jerks" when scrolling. The original script I posted smoothly scrolled
> the DIV...


It was a quick fix. I woke up that morning and the first thing that came
to my mind was: "If the user scrolls the page, the DIV will shift." Odd, I
know. As I hadn't had anything back from the OP, I thought I should just
add the extra code as soon as possible. I should have just tested though
about it more in the first place.

If you want smoother movement, I could add it if you want.

> Also, I tried replacing document.body with document.documentElement, and
> it works perfectly in IE, but not in Firefox :-/


Firefox doesn't report properties like scrollTop on the HTML element
(which is what documentElement refers to). However, as Firefox does
support the fixed position value, there isn't much point in worrying about
that.

> I think I will use your script, with a little modification :-) Thanks a
> bunch.


You're welcome.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Mick White 10-04-2004 05:53 PM

Re: <!DOCTYPE> breaking a script?
 
Duncan Booth wrote:

>
> Have a look at IE7: http://dean.edwards.name/IE7/compatibility/fixed.html


http://dean.edwards.name/IE7/ie7-standard-p.js

interesting source...

Mick


All times are GMT. The time now is 03:13 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57