发现一个问题,这个飘窗只能在初始页面大小的范围内移动,如果网页往下滚动了,飘窗就看不到了,有没有办法实现随着网页的滚动,飘窗始终在窗口范围内移动?
修改以下几处即可
w_h = parseInt($(window).height())+$(window).scrollTop(); function isTop(pos, w_w, w_h, d_w, d_h){//飘窗到达上边距 return (pos.top<=$(window).scrollTop()) ? true : false; } $(window).on('resize', function(){//窗口大小变动时重新设置运动相关参数 w_w = parseInt($(window).width()); w_h = parseInt($(window).height())+$(window).scrollTop(); max_l = w_w - d_w; max_t = w_h - d_h; }); $(window).on('scroll', function(){//窗口滚动时重新设置运动相关参数 w_w = parseInt($(window).width()); w_h = parseInt($(window).height())+$(window).scrollTop(); max_l = w_w - d_w; max_t = w_h - d_h; if(isTop(position, w_w, w_h, d_w, d_h)){ position.top=$(window).scrollTop(); } });