Search code examples
jqueryprettyphoto

Fullscreen image scrolling with mouse


I want to make a fullscreen image (opened with lightbox Expand image) that is overflowing the screen size to scroll with the mouse overing of the sides or corners of the window -> eg. when the mouse is in the right corner - the image scrolls to the right, if it is in the bottom right corner - to the right and bottom.

Is there any jQuery plugin which can accomplish this? Or a HTML5/CSS3 method?


Solution

  • I've found this snippet, it works like a charm with a little tweaking:

    // Variables for current position
    var x, y;
    
    function handleMouse(e) {
      // Verify that x and y already have some value
      if (x && y) {
        // Scroll window by difference between current and previous positions
        window.scrollBy(e.clientX - x, e.clientY - y);
      }
    
      // Store current position
      x = e.clientX;
      y = e.clientY;
    }
    
    // Assign handleMouse to mouse movement events
    document.onmousemove = handleMouse;