<script type="text/javascript">
<!--
var step = 1;
var delay = 10;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
var name = navigator.appName;
var xPos=0;
var yPos=0;
if(name == "Microsoft Internet Explorer") name = true;
else name = false;
xPos = 20;
if(name) yPos = document.body.clientHeight;
else yPos = window.innerHeight;
function changePos() {
if(name) {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = moveDiv.offsetHeight;
Woffset = moveDiv.offsetWidth;
moveDiv.style.left = xPos + document.body.scrollLeft;
moveDiv.style.top = yPos + document.body.scrollTop;
}
else {
height = window.innerHeight;
width = window.innerWidth;
Hoffset = document.moveDiv.clip.height;
Woffset = document.moveDiv.clip.width;
document.moveDiv.pageY = yPos + window.pageYOffset;
document.moveDiv.pageX = xPos + window.pageXOffset;
}
if (yon) {
yPos = yPos + step;
}
else {
yPos = yPos - step;
}
if (yPos < 0) {
document.all["moveDiv"].innerHTML = xPos;
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
document.all["moveDiv"].innerHTML = yPos;
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}
else {
xPos = xPos - step;
}
if (xPos < 0) {
document.all["moveDiv"].innerHTML = yPos;
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
document.all["moveDiv"].innerHTML = xPos;
xon = 0;
xPos = (width - Woffset);
}
}
function start() {
if(name) moveDiv.visibility = "visible";
else document.moveDiv.visibility = "visible";
interval = setInterval('changePos()',delay);
}
function pauseResume() {
if(pause) {
clearInterval(interval);
pause = false;
}
else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
//-->
</script>
Trådstart#1
Jag skulle behöva ha hjälp med att ändra min siffra i div-taggen då den nuddar väggen!!
<body onClick="pauseResume();">
<div id="moveDiv" style="position:absolute;top:400;left:400;background-color:FF6666;
width:100px;height:100px;text-align:center;font-weight:bold;font-size:20pt;">1</div>
<script language="Javascript">
var step = 1;
var delay = 10;
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) {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = moveDiv.offsetHeight;
Woffset = moveDiv.offsetWidth;
moveDiv.style.left = xPos + document.body.scrollLeft;
moveDiv.style.top = yPos + document.body.scrollTop;
}
else {
height = window.innerHeight;
width = window.innerWidth;
Hoffset = document.moveDiv.clip.height;
Woffset = document.moveDiv.clip.width;
document.moveDiv.pageY = yPos + window.pageYOffset;
document.moveDiv.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);
}
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() {
if(name) moveDiv.visibility = "visible";
else document.moveDiv.visibility = "visible";
interval = setInterval('changePos()',delay);
}
function pauseResume() {
if(pause) {
clearInterval(interval);
pause = false;
}
else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
</script>
en funktion som ändra nummret är väl vad som behövs men jag kan inte komma på det..