var mouseLastX=0, mouseLastY=0; var posX=0, posY=0; var viewWidth = 540; var viewHeight = 1; var start=0; function scrollMouse(e){ var sbox = $('main'); var thisX = e.clientX; var thisY = e.clientY; if (mouseLastX>0) { dx = thisX - mouseLastX; posX = posX+dx; if (posX <0) posX =0; if (posX > (sbox.scrollWidth - viewWidth)) posX = sbox.scrollWidth - viewWidth; sbox.scrollLeft = posX; } if (mouseLastY>0) { dy = thisY - mouseLastY; posY = posY+dy; if (posY <0) posY =0; if (posY > (sbox.scrollHeight - viewHeight)) posY = sbox.scrollHeight - viewHeight; sbox.scrollTop = posY; }; mouseLastX = thisX; mouseLastY = thisY; }; startScrollMouse = function (){ start = 1; document.onmousemove= scrollMouse; }; stopScrollMouse = function (){ start = 0; document.onmousemove = null; mouseLastX=0; mouseLastY=0 };