当前页面: JAVA 编程资料牛鼻论坛 → AJAX & JavaScript 技术→怎么增加网页挂件 |
把下面的文件保存为CSS样式表,然后再加到你的网页中去:
body {cursor: url('cursors/body.ani');}
其中两个单引号之间的是你自定义光标的文件路径。
把下面的文件保存为网页,其中图片的文件名是float.gif:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>飘动图片</title>
</head>
<body>
<div id="img" style="position: absolute; z-index: 2; left: 100; top: 126; width: 100; height: 75">
<img src="float.gif" width="100" height="75"></div>
<script language=javascript>
<!-- Begin
var xPos = 200;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 20;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img.offsetHeight;
Woffset = img.offsetWidth;
img.style.left = xPos + document.body.scrollLeft;
img.style.top = yPos + document.body.scrollTop;
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);
}
if (xon) {
xPos = xPos + step;
}
else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function start() {
img.visibility = "visible";
interval = setInterval('changePos()', delay);
}
function pause_resume() {
if(pause) {
clearInterval(interval);
pause = false;
}
else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
// End -->
</script>
</body>
</html>