Jake said:
Rob: But you have the tags in your js file code:
'<script type="text/javascript">'
and then '</script>' at the end. These are what I referred to when I
asked:
'Is it necessary to remove the <script></script> tags within the .js
file because of the duplication?'
The original script, as posted, did not work at all in any browser I
tried it in, it was missing a line of code. So I've mucked around to
get it going how I think you wanted it...
If what you mean by 'sliding banner' is that it stays at some offset
from the top of the page regardless of scrolling, and the text stays on
the right, then the following is all you need. It sets anything inside
'staticbanner' to right-align so you don't need anything to do with left
scrolling, window width or left positioning, it all happens 'cause of
CSS. Just set some right padding on the enclosed A to keep it away from
the right edge (I've used 10px).
Your banner can be any size and will just sit in the 'right' place... ha
ha.
The script is hugely simplified and should use far less resources than
what was originally posted.
Note that you should be using HTML 4 strict, which affects positioning
and you must add units to style measurements (e.g. using 'px' when
setting 'crossobj.style.top').
It is tested in Firefox and IE, I can't test in old Netscape. I got the
code for scrollT() from Quirksmode, it should work in any IE or 'zilla
based browser.
<URL:
http://www.quirksmode.org/index.html?/js/display.html>
If you want the script in the page, paste the contents of the script
between the script tags and remove the src attribute.
The HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"
http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>slider play</title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<style type="text/css">
body { margin: 0; padding: 0;}
</style>
</head>
<body>
<div style="height: 150px; background-color: #ddddff;"></div>
<!-- static slider -->
<div id="staticbanner"
style="position:absolute; top: 120px;
width: 100%; text-align: right;">
<a href="linkpage.htm?adslider" target="_blank"
style="padding: 0 10px 0 0;">BannerText</a>
</div>
<!-- Insert script element -->
<script type="text/javascript" src="slider.js"></script>
<div style="height: 1000px;">Make space for scrolling</div>
</body></html>
The script 'slider.js'
// Get a reference to 'staticbanner'
var crossobj = document.getElementById?
document.getElementById('staticbanner'): document.all?
document.all.staticbanner : document.staticbanner;
// Keeps the banner 120px from top
function positionit(){
// If browser supports style
if ( crossobj.style ) {
crossobj.style.top = scrollT() + 120 + 'px';
}
// If browser supports layers
else if ( document.layers ){
crossobj.top = scrollT() + 130 + 'px';
}
}
// Returns the number of pixels the page has scrolled down
function scrollT() {
if (self.pageYOffset) return self.pageYOffset;
if (document.documentElement
&& document.documentElement.scrollTop)
return document.documentElement.scrollTop;
if (document.body) return document.body.scrollTop;
}
// Start the timer
setInterval('positionit()',200)