function updateZoom() {
      // Stop the zoom resize to go outside picture (top)
      if(zoom.getBoundingClientRect().top < 0) {
         zoom.style.top = -imagePosition.top + 'px';
      }
      // Stop the zoom resize to go outside picture (bottom)
      if(zoom.getBoundingClientRect().bottom > window.innerHeight) {
         zoom.style.top = window.innerHeight - imagePosition.top - zoom.getBoundingClientRect().height +  'px';
      }

      // Stop the zoom resize to go outside picture (right)
      if(zoom.getBoundingClientRect().right > window.innerWidth) {
         zoom.style.left = window.innerWidth - zoom.getBoundingClientRect().width - imagePosition.left + 'px';
      }
      // Stop the zoom resize to go outside picture (left)
      if(zoom.getBoundingClientRect().left < 0) {
         zoom.style.left = -imagePosition.left + 'px';
      }
   }
/**
    * Update the position of the zoom so it cannot move outside the window
    */
Update the position of the zoom so it cannot move outside the window
Update the position of the zoom so it cannot move outside the window
function updateZoom() {
      if(zoom.getBoundingClientRect().top < 0) {
         zoom.style.top = -imagePosition.top + 'px';
      }
      if(zoom.getBoundingClientRect().bottom > window.innerHeight) {
         zoom.style.top = window.innerHeight - imagePosition.top - zoom.getBoundingClientRect().height +  'px';
      }
      if(zoom.getBoundingClientRect().right > window.innerWidth) {
         zoom.style.left = window.innerWidth - zoom.getBoundingClientRect().width - imagePosition.left + 'px';
      }
      if(zoom.getBoundingClientRect().left < 0) {
         zoom.style.left = -imagePosition.left + 'px';
      }
   }
function updateZoom ( ) { if ( zoom . getBoundingClientRect ( ) . top < 0 ) { zoom . style . top = - imagePosition . top + 'px' ; } if ( zoom . getBoundingClientRect ( ) . bottom > window . innerHeight ) { zoom . style . top = window . innerHeight - imagePosition . top - zoom . getBoundingClientRect ( ) . height + 'px' ; } if ( zoom . getBoundingClientRect ( ) . right > window . innerWidth ) { zoom . style . left = window . innerWidth - zoom . getBoundingClientRect ( ) . width - imagePosition . left + 'px' ; } if ( zoom . getBoundingClientRect ( ) . left < 0 ) { zoom . style . left = - imagePosition . left + 'px' ; } }
Update the position of the zoom so it cannot move outside the window
Update the position of the zoom so it cannot move outside the window
// Stop the zoom resize to go outside picture (top) // Stop the zoom resize to go outside picture (bottom) // Stop the zoom resize to go outside picture (right) // Stop the zoom resize to go outside picture (left)