-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
Description
See https://jsfiddle.net/mnhjsw8k/
Notice how an error is thrown when trying to obtain the scroll parent for an element that is hidden and has position:absolute.
The error is caused by the code's inability to obtain elm's offsetParent here (it is null when hidden):
Line 1033 in 41a1a6e
| var offsetParent = elm.offsetParent; |
The offsetParent (which is now null) is passed to Fit.Dom.Contained(..) where it is not allowed to be null:
Line 1049 in 41a1a6e
| if (pos === "absolute" && elm !== offsetParent && Fit.Dom.Contained(elm, offsetParent) === false) |
Code to reproduce:
HTML
<div>
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<span id="x">Find my scroll parent</span>
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
<br> Hello world
</div>
CSS
body
{
font-family: verdana;
font-size: 14px;
color: #333;
}
div
{
width: 400px;
height: 200px;
border: 1px solid orange;
padding: 1em;
overflow: auto;
position: relative;
}
span
{
/* Combination of display:none and position:absolute triggers error */
display: none;
position: absolute;
top: 0;
right: 0;
}
JS
try
{
Fit.Dom.GetScrollParent(document.querySelector("#x"));
alert("Scroll position obtained");
}
catch (err)
{
alert(err);
}
Reactions are currently unavailable