calcShift(
    conToImageRatio,
    containerSize,
    imageSize,
    focusSize,
    toMinus
  ) {
    const containerCenter = Math.floor(containerSize / 2); // Container center in px
    const focusFactor = (focusSize + 1) / 2; // Focus point of resize image in px
    /* Can't use width()as images may be display:none */
    const scaledImage = Math.floor(imageSize / conToImageRatio);
    let focus = Math.floor(focusFactor * scaledImage);
    if (toMinus) focus = scaledImage - focus;
    let focusOffset = focus - containerCenter; // Calculate difference between focus point & center
    const remainder = scaledImage - focus; // Reduce offset if necessary so image remains filled
    const containerRemainder = containerSize - containerCenter;
    if (remainder < containerRemainder) focusOffset -= containerRemainder - remainder;
    if (focusOffset < 0) focusOffset = 0;

    return (focusOffset * -100) / containerSize;
  }
// Calculate the new left/top percentage shift of an image
Calculate the new left/top percentage shift of an image
Calculate the new left / top percentage shift of an image
calcShift(
    conToImageRatio,
    containerSize,
    imageSize,
    focusSize,
    toMinus
  ) {
    const containerCenter = Math.floor(containerSize / 2); 
    const focusFactor = (focusSize + 1) / 2; 
    const scaledImage = Math.floor(imageSize / conToImageRatio);
    let focus = Math.floor(focusFactor * scaledImage);
    if (toMinus) focus = scaledImage - focus;
    let focusOffset = focus - containerCenter; 
    const remainder = scaledImage - focus; 
    const containerRemainder = containerSize - containerCenter;
    if (remainder < containerRemainder) focusOffset -= containerRemainder - remainder;
    if (focusOffset < 0) focusOffset = 0;
    return (focusOffset * -100) / containerSize;
  }
calcShift ( conToImageRatio , containerSize , imageSize , focusSize , toMinus ) { const containerCenter = Math . floor ( containerSize / 2 ) ; const focusFactor = ( focusSize + 1 ) / 2 ; const scaledImage = Math . floor ( imageSize / conToImageRatio ) ; let focus = Math . floor ( focusFactor * scaledImage ) ; if ( toMinus ) focus = scaledImage - focus ; let focusOffset = focus - containerCenter ; const remainder = scaledImage - focus ; const containerRemainder = containerSize - containerCenter ; if ( remainder < containerRemainder ) focusOffset -= containerRemainder - remainder ; if ( focusOffset < 0 ) focusOffset = 0 ; return ( focusOffset * - 100 ) / containerSize ; }
Calculate the new left/top percentage shift of an image
Calculate the new left / top percentage shift of an image
// Container center in px // Focus point of resize image in px /* Can't use width()as images may be display:none */ // Calculate difference between focus point & center // Reduce offset if necessary so image remains filled