Hey, I've been trying to get this to work, but can't seem
to. There
must be some inconsistency with the scope of the functions.
Could I get
some suggestions, or solutions?
Here is my code:
function kwObject ()
{
var layer;
var fader;
// Fade the opacity to 1.0 over a given time;
this.fadeIn = function (oTime)
{
if (fader) clearInterval(fader);
fader = setInterval("fade(1, 1/oTime)", 10);
}
// Fade the opacity to 0.0 over a given time;
this.fadeOut = function (oTime)
{
if (fader) clearInterval(fader);
fader = setInterval('fade(-1, 1/oTime)', 10);
}
// Proform fading
this.fade = function (dir, chunk)
{
if (layer && dir < 0.0 &&
layer.style.opacity > 0.0)
{
layer.style.opacity = layer.style.opacity - chunk;
alert(dir+", "+layer.style.opacity);
}
else if (layer && dir > 0.0 &&
layer.style.opacity < 1.0)
{
layer.style.opacity = parseInt(layer.style.opacity) +
chunk;
alert(dir+", "+layer.style.opacity);
}
else
{
clearInterval(fader);
}
}
this.setLayer = function (layerId)
{
layer = document.getElementById(layerId);
layer.style.opacity = 1.0;
}
}
It's pretty straight forward to figure out what I am trying
to do. I
just can't figure out why the setInterval doesn't call the
function
thats inside the "Object". Here is how you set
up an instance of it:
<html>
<head>
<title>Layer Fade Test</title>
<script type="application/x-javascript"
src="Object.js" />
<script type="application/x-javascript">
var object;
function setup () {
object = new kwObject();
object.setLayer("data");
}
</script>
</head>
<body onload="setup()">
<div id='data'
onclick="object.fadeOut(100)">Fade
Me</div>
</body>
</html>
Thanks so much for your help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "OOP Javascript" group.
To post to this group, send email to OOP-Javascript googlegroups.com
To unsubscribe from this group, send email to
OOP-Javascript-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/OOP-Javascript
-~----------~----~----~----~------~----~------~--~---
|