onscroll Script dont work in IE

M

Martin Nadoll

Hi,

i use the following script for placing html-content while scrolling a page:

var oben;
var showscroll;
var footerdivApplicationScroll;
var scrollTop = document.body.scrollTop ||
document.documentElement.scrollTop;
var scrolLeft = document.body.scrollLeft ||
document.documentElement.scrollLeft;
function scrollLogo() {
var bt = document.body.scrollTop;
var et = document.documentElement ? document.documentElement.scrollTop
: null;
oben=logoMarginTop+(bt || et);

// control the values
showscroll = document.getElementById('showscroll');
showscroll.innerHTML = "Box wird gescrollt " +(bt || et)+" und oben:
"+oben;

// move the layer
footerdivApplicationScroll = document.getElementById('fapp');
footerdivApplicationScroll.style.marginTop = oben+'px';
oben=logoMarginTop;
}

It is fine in all Browsers, but it doesnt work in IE (i have 8.0)
Please dont ask me to position the layer with css...

Has someone a idea or can give me a tipp?

Thanks a lot,
Martin Nadoll
 
J

Jukka K. Korpela

i use the following script for placing html-content while scrolling a page:

Please provide a URL of the page (or a demo copy thereof). Your code
snippet has undefined identifiers and a function that is not called
anywhere, and it lacks the HTML content it is supposed to deal with.

And please describe what you are trying to accomplish and how it fails.
"It doesnt work" is not a description.
 
M

Martin Nadoll

ok, i try to make it easier:

i have a function in a external javascript-file:

function scrollLogo() {
window.alert("hello");
}

i try to fire it from the <body> tag:
<body onscroll="scrollLogo()">

works in all browsers but not in IE (i only tried IE 8.0)
no alert is seen in IE.
But <body onload="scrollLogo()"> works fine in IE, the alert is shown.

I hope, this is more clear and easy.
Maybe someone can help me with that.

Thanks again,
Martin Nadoll



Am 24-May-11 11:36 AM, schrieb Martin Nadoll:
 
T

Thomas 'PointedEars' Lahn

Martin said:
i have a function in a external javascript-file:

function scrollLogo() {
window.alert("hello");
}

i try to fire it from the <body> tag:
<body onscroll="scrollLogo()">

works in all browsers but not in IE (i only tried IE 8.0)
no alert is seen in IE.

It is seen in IE 7.0.5730.12CO on Windows XP SP3. I added the listener
dynamically (to a randomly chosen [X]HTML document), but that should not
make a difference.
But <body onload="scrollLogo()"> works fine in IE, the alert is shown.

Perhaps a pop-up blocker is the culprit? Is the scrollLogo() function
called at all? Does code other than window.alert(…) run?
[Top post]

<http://www.netmeister.org/news/learn2quote.html>


PointedEars
 
M

Martin Nadoll

no, the function is not called by IE...


Am 25-May-11 2:23 PM, schrieb Thomas 'PointedEars' Lahn:
Martin said:
i have a function in a external javascript-file:

function scrollLogo() {
window.alert("hello");
}

i try to fire it from the<body> tag:
<body onscroll="scrollLogo()">

works in all browsers but not in IE (i only tried IE 8.0)
no alert is seen in IE.

It is seen in IE 7.0.5730.12CO on Windows XP SP3. I added the listener
dynamically (to a randomly chosen [X]HTML document), but that should not
make a difference.
But<body onload="scrollLogo()"> works fine in IE, the alert is shown.

Perhaps a pop-up blocker is the culprit? Is the scrollLogo() function
called at all? Does code other than window.alert(…) run?
[Top post]

<http://www.netmeister.org/news/learn2quote.html>


PointedEars
 
E

Evertjan.

Martin Nadoll wrote on 25 mei 2011 in comp.lang.javascript:
i have a function in a external javascript-file:

The external or internal placing has nothing to do with your Q.
function scrollLogo() {
window.alert("hello");
}

i try to fire it from the <body> tag:
<body onscroll="scrollLogo()">

works in all browsers but not in IE (i only tried IE 8.0)
no alert is seen in IE.
But <body onload="scrollLogo()"> works fine in IE, the alert is shown.

I hope, this is more clear and easy.
Maybe someone can help me with that.

Works with me, on Chrome, and on IE8 too.

However, better use a multiple scroll event stopper:

<script type="text/javascript">
var stopEvent=true; // stops reloadevent
setTimeout('stopEvent=false;',2000);

function scrollEvent() {
if (!stopEvent) {
setTimeout('alert("hello");stopEvent=false;',1000);
stopEvent=true;
};
};
</script>

<body onscroll="scrollEvent();">
 
J

Jukka K. Korpela

no, the function is not called by IE...

Well I guess that you have now isolated the problem, but the situation
is obscured by the lack of a URL of your test page and by your posting
style. (Good old Usenet style is much better, even though it is
advertized by the resident troll.)

The following minimal document illustrates the problem

<!doctype html>
<title>onscroll</title>
<body style="height:1000em" onscroll="alert('hello')">
</body>

The cause of the problem appears to be that on IE, the normal scroll
bars relate to the document as a whole, the <html> element, and not the
<body> element. The following document illustrates this:

<!doctype html>
<html onscroll="alert('hello from html')">
<title>onscroll</title>
<body style="height:1000em" onscroll="alert('hello')">
</body>

The simplest cross-browser way to achieve what you trying to accomplish
seems to make the assignment

document.onscroll = scrollLogo;

in JavaScript, after the page has loaded. Notice that this triggers the
event when the page is reloaded, if it has been scrolled away from the
initial position; I'm not sure whether this is a problem or a good thing
in this case.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top