Offset () of an enlarged item

jQuery documentation for offset()states:

In addition, the sizes may be incorrect when the user zooms in on the page; browsers do not detect an API to detect this condition.

However, is there a way so that I can calculate the correct offset in browsers in the touch environment when using a spread to increase page content?

I created a small sample demonstrating the problem: https://jsfiddle.net/dhykgsmp/4/ (open in Chrome). Scroll down and press the zoom button. Autofill input offset is incorrect.

Thanks.

+4
source share
2 answers

. root .

$.fn.oldOffset = $.fn.offset;
$.fn.offset = function () {

    var c = $.fn.oldOffset.apply(this, arguments);

    // root child element with zero offset
    var wrc = $('body').children().first().oldOffset();

    var needToFix = wrc.left > 0 || wrc.top > 0;
    if (needToFix) {
        return {
            left: c.left - wrc.left,
            top: c.top - wrc.top
        };
    } else {
        return c;
    }
}
+1

, , , "" " ", .style.top, Element.getBoundingClientRect() positionDropdown().

0

Source: https://habr.com/ru/post/1620578/


All Articles