View Full Version : question about object
if i have this code:
<script>
function scroller()
{
this.containerH = document.all.container.offsetHeight;
this.dataH = document.all.container.offsetHeight;
}
myscroller = new scroller()
alert(myscroller.dataH)
</script>
<body>
...
</body>
then that won't work cause the document.all.container doesn't exist when the alert runs.. so i thought i could use the <body onload="init()"> and use
function init()
{
myscroller = new scroller()
}
but then i can't refer to tat object outside the init function.. with variables you just set "var myscroller;" outside that function but that doesn't work with an object..
any ideas about this, how i should do it? i guess it's simple but i don't know how..
help!
chrismiceli
01-24-2003, 02:12 AM
try putting your code after your body.
i tried that.. can you see if why it's not working?
this is the code.. i'm building a scroller.
<HTML>
<HEAD>
<style type="text/css">
#container {position:absolute;width:200;height:200;overflow:hidden;background-color:red;}
#data {position:absolute;width:180;}
</style>
</HEAD>
<BODY onload="init()">
<div style="position:absolute;top:10;left:10;">
<a href="#" onmouseover="start('up')" onmouseout="stop()">upp</a>
<br><br>
<a href="#" onmouseover="start('down')" onmouseout="stop()">ner</a>
</div>
<div id="container">
<div id="data">
testtesttesttesttesttesttesttesttesttesttesttest<br>
testtesttesttesttesttesttesttesttesttesttesttest<br>
testtesttesttesttesttesttesttesttesttesttesttest<br>
testtesttesttesttesttesttesttesttesttesttesttest<br>
testtesttesttesttesttesttesttesttesttesttesttest<br>
testtesttesttesttesttesttesttesttesttesttesttest<br>
testtesttesttesttesttesttesttesttesttesttesttest<br>
testtesttesttesttesttesttesttesttesttesttesttest<br>
</div>
</div>
<script language="javascript">
var add = 5;
var test;
function scroller()
{
this.containerH = document.all.container.offsetHeight;
this.dataH = document.all.container.offsetHeight;
}
function shortcut()
{
this.containertop = document.all.container.style.top
this.datatop = document.all.data.style.top
}
function init()
{
document.all.container.style.top = 100;
document.all.container.style.left = 100;
document.all.data.style.top = 10;
document.all.data.style.left = 10;
}
function start(arg)
{
test = true;
if (arg == "up") up();
else if (arg == "down") down()
}
function up()
{
if(test)
{
document.all.data.style.top = add;
add-=5;
setTimeout("up()",30);
}
}
function down()
{
if(test)
{
myshortcut.datatop = add;
add+=5;
setTimeout("down()",30);
}
}
function stop()
{
test = false;
}
myscroller = new scroller()
myshortcut = new shortcut()
</script>
</BODY>
</HTML>
----
the line that's not working is the:
myshortcut.datatop = add;
but the:
document.all.data.style.top = add;
works just fine.. so it's something with the object.
what am i doing wrong?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.