MCPcopy
hub / github.com/jonom/jquery-focuspoint / calcShift

Function calcShift

js/jquery.focuspoint.js:61–74  ·  view source on GitHub ↗
(conToImageRatio, containerSize, imageSize, focusSize, toMinus)

Source from the content-addressed store, hash-verified

59
60 //Calculate the new left/top values of an image
61 var calcShift = function(conToImageRatio, containerSize, imageSize, focusSize, toMinus) {
62 var containerCenter = Math.floor(containerSize / 2); //Container center in px
63 var focusFactor = (focusSize + 1) / 2; //Focus point of resize image in px
64 var scaledImage = Math.floor(imageSize / conToImageRatio); //Can't use width() as images may be display:none
65 var focus = Math.floor(focusFactor * scaledImage);
66 if (toMinus) focus = scaledImage - focus;
67 var focusOffset = focus - containerCenter; //Calculate difference between focus point and center
68 var remainder = scaledImage - focus; //Reduce offset if necessary so image remains filled
69 var containerRemainder = containerSize - containerCenter;
70 if (remainder < containerRemainder) focusOffset -= containerRemainder - remainder;
71 if (focusOffset < 0) focusOffset = 0;
72
73 return (focusOffset * -100 / containerSize) + '%';
74 };
75
76 //Re-adjust the focus
77 var adjustFocus = function($el) {

Callers 1

adjustFocusFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected