繁体   English   中英

如果div的底部和屏幕匹配,则将div粘在屏幕上

[英]stick div to screen if bottom of div and screen matches

大家好,我正在做一个项目,在该项目中,当页面底部位于屏幕底部时,我必须将div粘贴到屏幕上(禁用滚动)。 我在页面中有两个div,并且两个div的高度都是可变的。 我要贴上div2并滚动div1。

<script>
  var divheight
  var scrolltop
  var screenheight
  if(divheight-scrolltop <= screenheight){ 
  /* now stick the div wherever it is i can not 
  use fixed position as both the divs are floating and
   fixing the position will make it to change the position*/ } 
   else { /*un stick the div*/ }
 </script>

我不知道该怎么办,否则请帮助我

使功能在滚动时触发。 该功能的主要目的是查看屏幕高度和div底部之间的差异。 一旦差异小于或等于零,则将css位置修改为固定。 这对你有帮助

(function ($) {
  $('.DIV1').scroll(function () {
    var $this = $(this),
        win_ht = $(window).height(),
        div_ht = $this.height(),
        div_bot = $this.offset().top + div_ht;
    if (win_ht - div_bot <= 0) {
        $this.css({
            'position': 'fixed',
            'bottom': '0'
        })
    }
  });
})(jQuery);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM