The document.onload event doesn't exist in at least some browsers. Firefox is one of them. It should be window.onload, or if executed in the global scope, simply onload.
Ideally you should be using an add/attach event thing, or even a document ready event. The syntax for either of those is different than for onload.
That said, this works:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="jasoop.js"></script>
<script type="text/javascript">
var myElement;
onload = function() {
myElement = new Effect("slide");
}
</script>
<style type="text/css">
#slide {
background: black;
width: 480px;
height: 360px;
}
</style>
</head>
<body>
<div id="slide" onclick="myElement.fadeOut(2, 'normal');"></div>
</body>
</html>
A document ready version:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="jasoop.js"></script>
<style type="text/css">
#slide {
background: black;
width: 480px;
height: 360px;
}
</style>
</head>
<body>
<div id="slide" onclick="myElement.fadeOut(2, 'normal');"></div>
<script type="text/javascript">
var myElement = new Effect("slide");
</script>
</body>
</html>
Using your own slightly cumbersome addEvent function:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="jasoop.js"></script>
<script type="text/javascript">
(function(el){
var myElement;
var myClick = function(){
myElement.fadeOut(2, 'normal');
};
var myOnload = function() {
myElement = new Effect(el);
myElement.addEvent('click', myClick);
};
Effect.prototype.addEvent.call({element: window}, 'load', myOnload);
})('slide');
</script>
<style type="text/css">
#slide {
background: black;
width: 480px;
height: 360px;
}
</style>
</head>
<body>
<div id="slide"></div>
</body>
</html>
Note: All these work using the jasoop version in the blog entry.
Bookmarks