定位锚点 遮罩层 距离顶部多少距离

刷新页面 回到顶部
window.onbeforeunload = function () {
        window.scrollTo(0, 0);
}
1
2
3
4
5
6
距离顶部多少距离
$('body,html').scrollTop(180);
 
$('html,body').animate({
                        scrollTop:$("#collapse-payment-address .panel-body").offset().top - 100
                    }, 1000);
1
2
3
4
5
6
7
8
9
遮罩层
 
var msg = '<div class="mask-layer-hui" style="min-width: 100px;background-color: #000;filter: alpha(opacity=60);background-color: rgba(0,0,0,.6);color: #fff;border: none;box-shadow: none;border-radius: 2px;position: fixed;z-index: 19891018;top: 50%;left: 25%;right: 25%;width: 50%">';
    msg += '<div class="mask-layer-content" style="padding: 12px 25px;text-align: center;position: relative;line-height: 24px;word-break: break-all;overflow: hidden;font-size: 14px;overflow-x: hidden;overflow-y: auto;">'+content+'</div>';
    msg += '</div>';
    $("#checkout-checkout").append(msg);
    $(".mask-layer-hui").fadeIn().delay(3000).fadeOut('slow','swing',function () {
        $(".mask-layer-hui").remove();
    });

  

  

复制代码
var common=function(){};
Common.prototype={
onScrollEvent:function(){
    $(window).scroll(function(){
         if(common.isPageBottom()){
                console.log('滚动条到达页面的底部')
          }
     });
},
  
isPageBottom:function(){
        var winH = $(window).height(); //页面可视区域高度
        var pageH = $(document.body).height();//页面的高度
        var scrollT = $(window).scrollTop(); //滚动条top
        //这里做一个计算距离底部还差多少,下边跟0.02比就是,滚动条的高度小于页面可视区域高度的的2%
        var aa = (pageH-winH-scrollT)/winH;
        //这里做比较当他小于0.02的时候我就认为他已经到底部了,为再次请求数据做一个缓冲,提高浏览页面的流畅度
        if(aa<0.02){
            return true;
        }
        return false;
    },
}
复制代码

 

posted @   楼前竹  阅读(71)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示