Note that there are some explanatory texts on larger screens.

plurals
  1. POI can't access the visual location of an element with JS
    primarykey
    data
    text
    <p>I have a multi-column layout in a UIWebview (webkit control) but I'm having problems accessing the 'visual' location of an element. </p> <p>I shift tapX by 4096 (4 x 1024, where 1024 is the height of a 'columnated page'), and get the correct 'tapped' element, but I cannot tell whether I'm at the edge or in the middle of the element. I need the absolute top and left positions, so I can animate a layer effect over the top of the element using a rect of (e.left, e.top, width, height) - obtaining the correct e.left and e.top is proving tricky.</p> <p><code>tapElement.offsetTop</code> ignores the column layout and the transform does not appear to work.</p> <pre class="lang-js prettyprint-override"><code>var tapElement = document.elementFromPoint(tapX, tapY); if (!tapElement) return; var realLeft = window.getComputedStyle(tapElement).getPropertyValue("offsetLeft"); var realTop = window.getComputedStyle(tapElement).getPropertyValue("offsetTop"); </code></pre> <hr> <p>Solution:</p> <pre><code>// Figuring out the real top and left positions is difficult // under the CSS3 multi column layout... But this works :) /* // jQuery method var realLeft = $(tapElement).offset().left; var realTop = $(tapElement).offset().top; */ // DOM method var box = tapElement.getBoundingClientRect(); var doc = tapElement.ownerDocument; var docElem = doc.documentElement; var body = doc.body; var win = window; var clientTop = docElem.clientTop || body.clientTop || 0; var clientLeft = docElem.clientLeft || body.clientLeft || 0; var scrollTop = win.pageYOffset || docElem.scrollTop || body.scrollTop; var scrollLeft = win.pageXOffset || docElem.scrollLeft || body.scrollLeft; var realTop = box.top + scrollTop - clientTop; var realLeft = box.left + scrollLeft - clientLeft; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload