I tried to implement a div on my website, that sticks to the top of the browser as soon as it scrolls out of the viewport. I found a script that does this pretty good and it works well on the desktop. When I test it on the iphone I have a short lag where the div scrolls out for about a half second and pop then up at the desired location. Has anybody a clue how I could tweak that script?
Here is the link: jsFiddle
Thanks for your help!
function sticky_relocate() {
var window_top = $(window).scrollTop();
var div_top = $('#sticky-anchor').offset().top;
if (window_top > div_top) {
$('#sticky').addClass('stick');
$('#sticky-anchor').height($('#sticky').outerHeight());
} else {
$('#sticky').removeClass('stick');
$('#sticky-anchor').height(0);
}
}
$(function() {
$(window).scroll(sticky_relocate);
sticky_relocate();
});