Skip to content

Instantly share code, notes, and snippets.

@adatta02
Created October 29, 2012 21:56
Show Gist options
  • Save adatta02/3976807 to your computer and use it in GitHub Desktop.
Save adatta02/3976807 to your computer and use it in GitHub Desktop.
Scroll an element with the page with a debounced event.
jQuery(document).ready( function(){
jQuery(window).scroll( function(){
if( jQuery(window).scrollTop() > 1940 ){
if( jQuery("#ss-ad").css("position") == "absolute" ){
if( window.criteoTimer ){
window.clearTimeout( window.criteoTimer );
}
window.criteoTimer = window.setTimeout(function(){
jQuery("#ss-ad").animate( {"top": (jQuery(window).scrollTop() - 300)} );
}, 300);
}else{
jQuery("#ss-ad").css(
{position: "absolute", top: (jQuery(window).scrollTop() - 300) + "px", right: "10px"}
);
}
}else{
jQuery("#ss-ad").css( {position: "relative", top: "", right: ""} );
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment