Created
October 29, 2012 21:56
-
-
Save adatta02/3976807 to your computer and use it in GitHub Desktop.
Scroll an element with the page with a debounced event.
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
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