A position query is a simple expression used to filter elements by their position on the screen.
An expression is made up of a property and a value. The property describes the measured edge of the element by using top
, bottom
, left
, or right
. The value describes the measured edge and position of the screen by adding before
or after
.
For example, the following query checks if the element is above the screen. It does this by checking if the bottom of the element comes before the top of the screen.
<div position="(bottom: before-top)"></div>
The and
operator is used to link multiple queries. For example, the following query checks if the element is on screen. It does this by checking if the top of the element comes before the bottom of the screen and also if the bottom of the element comes after the top of the screen.
<div position="(top: before-bottom) and (bottom: after-top)"></div>
The or (,
) operator is used to separate queries. For example, the following query checks if the element is off screen. It does this by checking if the top of the element comes after the bottom of the screen or if the bottom of the element comes before the top of the screen.
<div position="(top: after-bottom), (bottom: before-top)"></div>
A preceding measurement is used to modify the measured edge of the screen. For example, the following query checks if the end of the element is nearing the bottom of the screen. It does this by checking if the bottom of the element is -100px before the bottom of the screen.
<div position="(bottom: -100px before-bottom)"></div>
A second preceding measurement is used to modify the measured edge of the element. For example, the following query also checks if the halfway end of the element is nearing the bottom of the screen. It does this by checking if the bottom 50% of the element is -100px before the bottom of the screen.
<div position="(bottom: 50% -100px before-bottom)"></div>