上下限-板块浮动 插件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="../jquery-3.2.1.min.js"></script>          <!--必要:  引入jquery-->
    <style>     /*测试css*/
        *{  margin: 0; padding: 0; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
        header{  width: 100%;height: 150px;}
        .body{  border: 1px solid #000;height: 3000px; }
        footer{  width: 100%;height: 100px;}
        .float div{  height: 100%; width: 200px; background-color: rgba(255,5,5,.3);  } /*浮动节点的子孙元素css*/
    </style>
</head>
<body>
    <header></header>
    <div class="body">
        <div class="float">
            <div>
                <h1>名称:  上下限浮动封装</h1>
                <h3>用法:  使用dom节点引用插件[浮动区域的宽高为窗口宽高]</h3>
                <p >备注:  引用的节点在jquery中已经写好css,只需要对其子孙元素添加css</p>
                <p >备注:  插件的浮动范围在父级容器范围内,父级会自动添加最小高度为窗口高度</p>
                <h6>必要:  注意引入jquery</h6>
            </div>
        </div>
    </div>
    <footer></footer>
</body>
</html>
<script>
    (function () {
        $.fn.float = function () {      var fn = this;  var par = this.parent();     //开发者: 刘武星
            this.css({display:'block',position:'fixed',width:'100%',height:'100%',overflow:'hidden',visibility:'collapse'});   //当前css
            this.children().css('visibility','visible');        //子级显示
            $(window).resize(function () {                      //窗口事件
                $(par).css({'min-height':$(fn).height()});       //父元素最小高度
                $(fn).css({top:$(par).offset().top});
            });$(window).resize();
            $(window).scroll(function () {                      //滚动事件
                var min = $(par).offset().top,max = (min+$(par).height())-$(fn).height(),do_t = $(document).scrollTop();    //变量 上限-下限-当前
                if(do_t<min){ $(fn).css('top',min-do_t);}
                else if(do_t>max){ $(fn).css('top',max-do_t); }
                else{ $(fn).css('top','0'); }
            });$(window).scroll();
        }
    })(jQuery);

    $('.float').float();	//引用插件
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值