2017-04-05 50 views
0

在下面的滾動功能因素,我想弄清楚我是如何通過一定數目的像素的晃過股利pg-selection的底部(比方說15像素)。如何在附加的底部PX在一個窗口中滾動功能

像這樣:

enter image description here

我試圖修改`bottom_of_element變量的方式不同,但都沒有奏效。我想:

var bottom_of_element = $('#pg-selection').offset({bottom: 15}).top + $('#pg-selection').outerHeight(); 

var bottom_of_element = $('#pg-selection').offset().top.bottom 15 + $('#pg-selection').outerHeight(); 

有誰知道我需要做什麼?

我有以下滾動功能:

$(window).scroll(function() { 
    var top_of_element = $('#pg-selection').offset().top; 
    var bottom_of_element = $('#pg-selection').offset().top + $('#pg-selection').outerHeight(); 
    var bottom_of_screen = $(window).scrollTop() + $(window).height(); 

    if ((bottom_of_screen > top_of_element) && (bottom_of_screen < bottom_of_element)) { 
     console.log(" PG Showing"); 
     $('#cal-selected-thumb').fadeIn(400); 
    } 
    else { 
     console.log(" PG Not Showing"); 
     $('#cal-selected-thumb').fadeOut(400); 
    } 
}); 

回答

1

你的代碼工作正常,你忘了在bottom_of_element例子第二個例子「+」。我試過這個,它的功能就像一個魅力:

var bottom_of_element = $('#pg-selection').offset().top + $('#pg-selection').outerHeight() + 200; 
+0

感謝您的幫助! – Paul

相關問題