Generic page type
Paralax Posted on:
Going back to our HTML, we see that even though we scaled the image up so that it would be perceived at the same size, the element has a certain offset from the top. Let’s try correct this by solving for the top gap
x " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">x x :
h " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">h h is the height of the element in the background (E F " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">E F E F )
s " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">s s is the scale applied. So, s . h = E 2 F 2 " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">s . h = E 2 F 2 s . h = E 2 F 2
v 2 " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">v 2 v 2 is half the height of the viewport
e " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">e e is the vertical distance from the perspective origin to the element center, and e 1 " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">e 1 e 1 its projection on the viewport
1 + z p - z " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">1 + z p − z 1 + z p - z is the factor any height at z " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">z z distance is multiplied with to result in the projected height.
Using the constraint that on the viewport projection: x + E 2 ’ O ’ + e 1 " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">x + E 2 ’ O ’ + e 1 x + E 2 ’ O ’ + e 1 is half of the viewport:
x + s 2 ⋅ h ⋅ ( 1 + z p - z ) + e ⋅ ( 1 + z p - z ) = v 2 " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">x + s 2 ⋅ h ⋅ ( 1 + z p − z ) + e ⋅ ( 1 + z p − z ) = v 2 x + s 2 ⋅ h ⋅ ( 1 + z p - z ) + e ⋅ ( 1 + z p - z ) = v 2
x = h 2 ⋅ ( 1 - s ) + h ⋅ z ⋅ 1 - s 2 ⋅ ( p - z ) – v ⋅ z 2 ⋅ ( p - z ) " role="presentation" style="box-sizing: border-box; display: inline; line-height: normal; text-indent: 0px; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">