Created
July 15, 2015 12:50
-
-
Save wmadden/9ac5f060114d4cc8e68e to your computer and use it in GitHub Desktop.
fix_fixed.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define [ | |
'jquery' | |
], ($) -> | |
# Fix Fixed is a work around an iOS bug involving fixed positioned elements. | |
# Whenever the keyboard shows up, a fixed positioned element would reposition | |
# itself randomly on the screen. This work around adds the .fix-fixed class to the | |
# body in order to let fixed positioned elements change their position to absolute | |
# while the keyboard is shown. | |
# | |
# The solution presented here is used: http://dansajin.com/2012/12/07/fix-position-fixed/ | |
# + the scroll hack. | |
if Modernizr.ios | |
$body = $('body') | |
$(document) | |
.on 'focus', 'input, textarea', (e) -> | |
$body.addClass('fix-fixed') | |
.on 'blur', 'input, textarea', (e) -> | |
$body.removeClass('fix-fixed') | |
_.defer scrollFix | |
scrollFix = -> | |
# Sometimes the fix positioned element requires a scroll before it returns to its place. | |
# Some solutions use $(window).scrollTop(0), but that would actually change the expected | |
# position on the screen. This solution performs a scroll of only 1 pixel. | |
$(window).scrollTop(window.scrollY + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment