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

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