How can I use the relatively new Intersection Observer API to detect when input that’s currently focused goes outside the viewport, so that when it does, the focus on that input is removed?
The solution should work in Safari for iOS.
Here is my code so far:
document.addEventListener("DOMContentLoaded", _ => {
const focusedInput = document.activeElement
// ?
focusedInput.blur()
})
html { height: 100% }
html, body, main, section {
display: flex;
flex-grow: 1
}
main { flex-direction: column }
section {
justify-content: center;
align-items: center;
flex: 1 0 100%
}
<main>
<section>
<form action=submit method=post>
<fieldset>
<legend>Enter Your Details</legend>
<label>Email<br><input type=email name=email placeholder=jane@example.com></label><hr>
<label>Message<br><textarea name=briefing placeholder="Lorem ipsum dolor sit amet."></textarea></label><hr>
<input type=submit value=Submit>
</fieldset>
</form>
</section>
<section>
<h2>Second Page</h2>
</section>
</main>