大家好,我正在制作一个粘性订阅框,如下面的网站
我用了下面的js
$.fn.is_on_screen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = this.offset();
bounds.right = bounds.left + this.outerWidth();
bounds.bottom = bounds.top + this.outerHeight();
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
};
$(window).scroll(function(){ // bind window scroll event
if( $('#foot').length > 0 ) { // if target element exists in DOM
if( $('#foot').is_on_screen() ) { // if target element is visible on screen after DOM loaded
$('.subscribeBox').fadeOut(1000);
} else {
$('.subscribeBox').fadeIn(1000);
}
}
});
但问题是我必须再添加一项功能,当滚动量大于 200 时,订阅框变得可见,其他虎钳隐藏请给我一些建议如何做到这一点。