2012-11-23 71 views
0

如何在到達瀏覽器窗口的底部時,使返回頂部鏈接向上滑動到位置X(頁腳頂部),即當用戶已完全向下滾動頁面?返回頂部鏈接在瀏覽器底部,然後在頁腳頂部

現在,我的頁面有一個固定在窗口底部的功能性返回頂部鏈接。但是,在頁面末尾有一個頁腳,而且返回頁首鏈接需要保留(或反彈)在頁面尾部的頁腳頂部,而不是瀏覽器窗口的底部。

TopLink的腳本是:

//plugin 
jQuery.fn.topLink = function(settings) { 
    settings = jQuery.extend({ 
    min: 1, 
    fadeSpeed: 200 
    }, settings); 
    return this.each(function() { 
    //listen for scroll 
    var el = $(this); 
    el.hide(); //in case the user forgot 
    $(window).scroll(function() { 
     if($(window).scrollTop() >= settings.min) 
     { 
     el.fadeIn(settings.fadeSpeed); 
     } 
     else 
     { 
     el.fadeOut(settings.fadeSpeed); 
     } 
    }); 
    }); 
}; 

//usage w/ smoothscroll 
$(document).ready(function() { 
    //set the link 
    $('#top-link').topLink({ 
    min: 400, 
    fadeSpeed: 500 

    }); 
    //smoothscroll 
    $('#top-link').click(function(e) { 
    e.preventDefault(); 
    $.scrollTo(0,500); 
    }); 
}); 

回答

0

你可以只檢查,如果用戶向下滾動到頁面底部是這樣的:

$(window).scroll(function() {   
    if($(window).scrollTop() + $(window).height() == $(document).height()) { 
     console.log("bottom reached"); 
    }    
}); 

如果到達底部,您可以設置的位置,你的鏈接,如你喜歡它或動畫它跳起來一點點或類似的東西。