views:

1395

answers:

2

Scroll.js is used for #bird block, which follows the page scrolling.

The main problem - it is working, if I remove the Doctype line, this one:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

and it doesnt work if doctype is on.

Here is the html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="scroll.js" type="text/javascript"></script>
</head>

<body>
<div style="position:relative; height:20000px">
    <div id="bird" style="position:absolute;left:0;top:20px;width:200px"></div>     
</div>
</body>
</html>

And js:

removed

Dont ask to remove the doctype, its needed.

A: 

there's one problem on your bird div, the style had width:200", should be width:200px" (add the units)

John Boker
fixed now, but its not a reason
Mike
+3  A: 

You need to replace this:

document.body.scrollTop

with this:

document.documentElement.scrollTop

scrollTop belongs to the <html> element in standards mode, rather than the <body> element.

(Note that document.body.scrollTop appears three times in your code.)

RichieHindle
I need to replace 3 times?
Mike
I have replaced all the "document.body.scrollTop" by "document.documentElement.scrollTop", and it works, but moves very slowly. How can I fix this?
Mike
is it possible to optimize this script? There is just one block on the page which follows the scrolling - #bird.
Mike
it movers veeery slowly, how to make it faster?
Mike
The code isn't complete - getElementById("baloon") fails because there's no such element. Plus I have stuff to do this month other than try to understand your code. 8-) At least your doctype problem is fixed.
RichieHindle
I have fixed the "baloon", it seems to be "bird" instead.
Mike
doctype fixed, by the blocks are flying very very slow, it must be faster at least 10 times - how ti fix that?
Mike
can you answer for my comments?
Mike
I'm sorry, but no, I don't have the time to understand or rewrite your code. You asked why your doctype was breaking your code, and now you know. I'm not trying to be rude, but please, stop asking me for further help with this code.
RichieHindle
thanks anyway..
Mike
Thanks for the accept. 8-)
RichieHindle
thanks for minus, huh
Mike
I didn't give you any minus (if that was aimed at me?)
RichieHindle
Woah, you deleted the text of the question! That's really not how Stack Overflow works - the idea is that the question and answer remain, so that the next person on the net whose scrollTop code doesn't work with a doctype can find the question and the answer. No wonder someone voted you down - you should roll back the question.
RichieHindle
this code is not mine, so I cant give to use it for all
Mike