jQuery scrollTop function
I have one page where the next page is fired when the user reaches the bottom of the page:
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
next_funtion();
}
});
However, I want next page to be fired when the user reaches 50% of the page height or 200 px fro开发者_高级运维m the top.
It's basic math. Without it, jQuery ain't gonna help you at all:
$(window).scroll(function() {
if (($(window).scrollTop() < 200) || ($(window).scrollTop() < $(document).height() / 2)) {
next_funtion();
You can try this code for ScrollTop Function
$('html,body').animate({
scrollTop: $('#'+id_name).offset()
}, "fast");
精彩评论