如何查明一个HTML元素是否在另一个HTML元件后面

How to find out if a HTML Element is behind another HTML Element?

本文关键字:HTML 另一个 是否 元素 一个 何查明      更新时间:2023-09-26

我有这个HTML:

HTML:

<div class="stave-container">
  <section id="Captcha"></section>
  <div id="horiz_container_outer">
     <img class="img1" />
       ...
     <img class="imgn"/>
  </div>
</div>
++++++++++++++++++++++++++++++++++++++++
+         +                            +
+#Captcha +  img | img | img | img     +
+         +  div#horiz_container_outer +
++++++++++++++++++++++++++++++++++++++++

#Captcha部分已修复!

div#horiz_container_outer是可滚动的,并且包含img元素!

我如何检测img元素何时在Div#Captcha后面,而滚动?

我的解决方案:

我把它放进jquery:.滚动功能

    $("#horiz_container_outer > img").each(function(){
      if( $("#Captcha").offset().left > $(this).offset().left )
        {
          console.log($(this).attr("class"));
        }
    })

如果你试图让屏幕的一部分不滚动(这听起来像,但我不太确定你的问题),那么符合标准的方法是:

.non-scroll-div {
  position:fixed;
}

但是,请记住兼容性:http://caniuse.com/#feat=css-固定

要将所有元素从一个div复制到另一个div,可以执行以下操作:

html

<div id="fixedDiv"></div>
<div id="stuff"><span>some stuff</span><br /><hr /></div>

js

document.getElementById("fixedDiv").innerHTML = document.getElementById("stuff").innerHTML;