Skip to content

Instantly share code, notes, and snippets.

@remvee
Last active August 29, 2015 14:13
Show Gist options
  • Save remvee/76566d1ecd0f300e067e to your computer and use it in GitHub Desktop.
Save remvee/76566d1ecd0f300e067e to your computer and use it in GitHub Desktop.
Detect on screen keyboard
(defn detect-keyboard-on-screen!
"Try to detect keyboard going on and off screen and toggle class on
the element when applicable."
[el class]
(let [former-height (atom (.-innerHeight js/window))]
(.addEventListener
js/window "resize"
#(let [focus (.-activeElement js/document)
height (.-innerHeight js/window)]
(gclasses/enable el class
(and (#{"INPUT" "TEXTAREA"} (.-tagName focus))
(< height @former-height)))
(reset! former-height height)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment