nschultz
06-19-2009, 03:00 AM
I have an overloaded div on my page that is scrolled by the position of the mouse in the window. It uses the onmousemove event to tell the position of the mouse. I want to use setInterval, or sonething, so that it will continually update the position of the mouse. It currently only registers the position when the mouse is moving, so it stops scrolling when the mouse stops moving.
The page is at http://www.nicnok.net/HTML/gallery/gallery.html
I'll assume you know how to get the html and so I won't take up space with it here. Thanks in advance for your help. The .js code is
document.onmousemove = CurPos;
function CurPos(evt) {
if (!evt) {
evt = window.event;
}
moveGal(evt.clientX);
}
function moveGal(xPos) {
var stageWidth = document.width;
var speed = 15;
var galWidth = document.getElementById("whole").offsetWidth;
var galX = document.getElementById("whole").offsetLeft;
var galView = document.getElementById("container").offsetWidth;
var xDist = xPos-(stageWidth/2);
galX = galX+((0-xDist)/speed);
if (galX>=0) {
galX = 0;
}
if (galX<=galView-galWidth) {
galX = galView-galWidth;
}
document.getElementById("whole").style.left=galX+"px";
}
The page is at http://www.nicnok.net/HTML/gallery/gallery.html
I'll assume you know how to get the html and so I won't take up space with it here. Thanks in advance for your help. The .js code is
document.onmousemove = CurPos;
function CurPos(evt) {
if (!evt) {
evt = window.event;
}
moveGal(evt.clientX);
}
function moveGal(xPos) {
var stageWidth = document.width;
var speed = 15;
var galWidth = document.getElementById("whole").offsetWidth;
var galX = document.getElementById("whole").offsetLeft;
var galView = document.getElementById("container").offsetWidth;
var xDist = xPos-(stageWidth/2);
galX = galX+((0-xDist)/speed);
if (galX>=0) {
galX = 0;
}
if (galX<=galView-galWidth) {
galX = galView-galWidth;
}
document.getElementById("whole").style.left=galX+"px";
}