tcmulder / aquamin

Aquamin WordPress Theme
3 stars 1 forks source link

Prevent parallax percentage from going out of bounds. #58

Closed tcmulder closed 11 months ago

tcmulder commented 11 months ago

Currently, maybe because of scroll speed/latency, it's possible to get numbers greater than 1 or less than 0 (i.e. negative) at the extreme edges of the viewport. This would prevent that:

let per = (top + height) / (win + height); // <-- this line exists but uses `const` instead of `let`
// don't go out of bounds
if (per < 0) {
    per = 0;
} else if (per > 1) {
    per = 1;
}
tcmulder commented 11 months ago

See this for a good example: https://codepen.io/tcmulder/pen/KKbaqQp?editors=0010

tcmulder commented 11 months ago

Also, as in the example above, consider adding a viewport/element height basis for percentage (make sure to document).