2017-04-05 46 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

相关问题