Skip to content

Fit.Dom.GetScrollParent(elm): Fails if element has position:absolute + display:none #210

@FlowIT-JIT

Description

@FlowIT-JIT

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):

var offsetParent = elm.offsetParent;

The offsetParent (which is now null) is passed to Fit.Dom.Contained(..) where it is not allowed to be null:

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions