Skip to content

Commit 6d82fc2

Browse files
committed
fix: center lens on cursor for images with border/padding
1 parent fe8c4ae commit 6d82fc2

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

packages/typo3-docs-theme/assets/js/image-zoom.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,16 @@
817817

818818
function updateLensPosition(x, y) {
819819
var rect = img.getBoundingClientRect();
820+
var style = window.getComputedStyle(img);
821+
var borderLeft = parseFloat(style.borderLeftWidth) || 0;
822+
var borderTop = parseFloat(style.borderTopWidth) || 0;
823+
var paddingLeft = parseFloat(style.paddingLeft) || 0;
824+
var paddingTop = parseFloat(style.paddingTop) || 0;
820825

821-
// Position lens centered on cursor (x,y are relative to image)
822-
var lensXPos = x - lens.offsetWidth / 2;
823-
var lensYPos = y - lens.offsetHeight / 2;
826+
// Position lens centered on cursor (x,y are relative to image content area)
827+
// Add border+padding offset since lens is positioned within imgWrapper
828+
var lensXPos = x + borderLeft + paddingLeft - lens.offsetWidth / 2;
829+
var lensYPos = y + borderTop + paddingTop - lens.offsetHeight / 2;
824830

825831
lens.style.left = lensXPos + 'px';
826832
lens.style.top = lensYPos + 'px';

packages/typo3-docs-theme/resources/public/js/theme.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)