Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何停止滚动与页脚重叠的div?_Javascript_Html_Css_Jquery - Fatal编程技术网

Javascript 如何停止滚动与页脚重叠的div?

Javascript 如何停止滚动与页脚重叠的div?,javascript,html,css,jquery,Javascript,Html,Css,Jquery,我想创建一个类似于ebuyer上的滚动div: 正如您所看到的,div标记停在页脚上方。我用什么代码来产生这样的效果 我最近使用了以下代码: 为了避免注释框与页脚重叠,我还需要添加哪些内容?首先,位置:已修复。然后,他们使用js来控制侧边栏的css属性:当侧边栏距离顶部足够远时,将其位置设置为固定 <style> #comments { float:left; width:450px; } #comment-wrapper { position: relativ

我想创建一个类似于ebuyer上的滚动div:

正如您所看到的,div标记停在页脚上方。我用什么代码来产生这样的效果

我最近使用了以下代码:

为了避免注释框与页脚重叠,我还需要添加哪些内容?

首先,位置:已修复。然后,他们使用js来控制侧边栏的css属性:当侧边栏距离顶部足够远时,将其位置设置为固定

<style>

#comments {
  float:left;
  width:450px;


}

#comment-wrapper {
  position: relative;
}

#commentWrapper { /* required to avoid jumping */
  left: 450px;
  position: absolute;
  margin-left: 35px;
  width:280px;

}

#comment {
  position: absolute;
  top: 0;
  margin-top: 20px;
  border-top: 1px solid purple;
  padding-top: 19px;
      background:#CCC;
        margin-left:200px;
}

h2 {
  font-family:georgia,serif;
}

#comments ol li {
  border-top: 1px solid purple;
}

#comments ol li:first-child {
  border-top: 0;
}

#comment.fixed {
  position: fixed;
  top: -5px;
}
</style>

    enter code here

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script>
$(function () {

  var msie6 = $.browser == 'msie' && $.browser.version < 7;

  if (!msie6) {
    var top = $('#comment').offset().top - parseFloat($('#comment').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();

      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#comment').addClass('fixed');
      } else {
        // otherwise remove it
        $('#comment').removeClass('fixed');
      }
    });
  }  
});
</script>

    enter code here

<div id="contentproduct">  

  <div id="comment-wrapper">
    <div id="comments">

    </div>

    <div id="commentWrapper">
      <div id="comment">
        <form>
        <p class="formrow"><label for="yourname">Name:</label>
          <input type="text" class="text" id="yourname" name="name" value=""></p>
        <p class="formrow"><label for="yoururl">URL:</label>
          <input type="text" class="text" id="yoururl" name="url"></p>
        <p class="formrow"><textarea rows="10" cols="35" name="body"></textarea></p>
        <p><input type="button" value="Preview comment"></p>
        </form>
      </div>
    </div>
  </div>