i downloaded a js code and it works with its own html index file. However, if i paste the <script>............everything </script> to my index, it doens't work. I tried to put it inside <head> </head> and i also tried inside <body> </body> ... they both don't work. Any suggestion? i am pertty new to js, please be specified. thank you.
code as below:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/text.css"/>
<style type="text/css">
body{background-image: url('/image/grasswindows.jpg');
background-position: 50% 100%;
background-attachment: fixed;
background-repeat: no-repeat;
}
#container{
position: absolute;
width: 800px;
height: 150px;
left: 50px;
top:200px;
}
</style>
<title>learning</title>
</head>
<body>
<div id="img" style="position:absolute;">
<img src="/icon/computer.png" onMouseDown="pauseResume();">
</div>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Justin Arruda (JArruda@mindspring.com) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! [url]http://javascript.internet.com[/url] -->
<!-- Begin
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
var name = navigator.appName;
//if(name == "Microsoft Internet Explorer") name = true;
//else name = false;
var xPos = 20;
if(name) var yPos = document.body.clientHeight;
else var yPos = window.innerHeight;
function changePos() {
if(name) {
height = 140;
Hoffset = img.offsetHeight;
Woffset = img.offsetWidth;
img.style.top = yPos + document.body.scrollTop;
}
else {
height = 140;
Hoffset = document.img.clip.height;
Woffset = document.img.clip.width;
document.img.pageY = yPos + window.pageYOffset;
document.img.pageX = xPos + window.pageXOffset;
}
if (yon) {
yPos = yPos + step;
}
else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
}
function start() {
if(name) img.visibility = "visible";
else document.img.visibility = "visible";
interval = setInterval('changePos()',delay);
}
function pauseResume() {
if(onmouseover) {
clearInterval(interval);
pause = false;
}
else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
// End -->
</script>
</body>
</html>