title: How do I check whether the right/left edge of an element is overlapping the side of it's container?
body: <p>I'm trying to display a right / left navigation arrow within a container (the arrows replace the existence of a scrollbar) when the corresponding edge of the content overlaps the container's sides. </p>
  
  <p>Also, when the content is scrolled all the way to the end and can't scroll any further, the arrow should disappear. </p>
  
  <p><img src="https://i.stack.imgur.com/jlR80.png" alt="enter image description here"></p>
  
  <p>My problem is, I'm confused as to how I write the function to check whether the element's contents are overlapping one edge or the other to hide one arrow or the other. </p>
  
  <p>I started writing logic like this:</p>
  
  <pre><code>function setArrows(elem){
      if (elem.scrollLeft() &gt; 0) { //scroll position is greater than zero
          // show left arrow
      } 
      if () { //scroll position is less than zero
          //show right arrow
      }
  }
  </code></pre>
  
  <p>but that doesn't seem to be the right logic. It sounded simpler in my head before I went to actually write the function.</p>
  
  <p><strong>How do I check whether the right/left edge of an element is overlapping the side of it's container?</strong></p>
  
  <p>Here's a Stack Snippet:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('#wrapper').scroll(function(){
    //check edges
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>div {
    padding: 0px;
    margin: 0px;
  }
  #wrapper {
    width: 500px;
    height: 100px;
    background-color: blue;
    overflow-x: scroll;
    overflow-y:hidden;
  }
  #content {
    width: 1000px;
    height: 100px;
    background-color: red;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="wrapper"&gt;
    &lt;div id="content"&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>