Created
May 3, 2012 17:01
-
-
Save dbox/2587257 to your computer and use it in GitHub Desktop.
iPhone position:fixed scroll fix
This file contains hidden or 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
// Fixed position fix | |
$('nav ul a').click(function(){ | |
// Find anchor position based on href | |
var y=Math.floor($($(this).attr('href')).offset().top); | |
// Add position fixed to nav | |
fixIt(); | |
// Animate to anchor position | |
$('html,body').animate({ scrollTop:y},500,function(){ | |
// On animation complete add position absolute to nav | |
// using the anchor position as top | |
$('nav ul, h1 a').css({position:'absolute',top:y}) | |
}) | |
// Prevent default | |
return false; | |
}); | |
// Add position fixed on touch move | |
$(document).bind('touchmove',fixIt); | |
function fixIt(){$('nav ul, h1 a').css({position:'fixed',top:0})} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment