title: jQuery - Sync Rotating Background-Image With Current Slide Indicator
body: <p>I'm using a simple jQuery script to implement a rotating background image on my masthead. I'd like to modify my current jQuery script to sync each background image to a corresponding bullet icon in a current slide indicator at the bottom of the page.</p>
  
  <p>I know that the simplest solution would be to use a rotating banner/carousel plugin, but I need total control over the styling and behavior. Overriding the plugin's CSS and restructuring my content might be more time consuming than to expand upon what I've already got working.</p>
  
  <p>I've posted a working example of my code below. I'd greatly appreciate any help with this issue. Thanks in advance!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
    var imgArr = new Array(
      'https://unsplash.it/1000/465?image=1',
      'https://unsplash.it/1000/465?image=2',
      'https://unsplash.it/1000/465?image=3',
      'https://unsplash.it/1000/465?image=4',
      'https://unsplash.it/1000/465?image=5'
    );
  
    var preloadArr = new Array();
    var i;
  
    for (i = 0; i &lt; imgArr.length; i++) {
      preloadArr[i] = new Image();
      preloadArr[i].src = imgArr[i];
    }
  
    var currImg = 1;
    var intID = setInterval(changeImg, 6000);
  
    function changeImg() {
      $('#banner-image').animate({
        opacity: 0
      }, 500, function() {
        $(this).css('background', 'url(' + preloadArr[currImg++ % preloadArr.length].src + ') top center no-repeat');
      }).animate({
        opacity: 1
      }, 500);
    }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#rotating-banner {
    background: #fff;
    box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.5);
    position: relative height: 465px;
    width: 1000px;
    margin: 0 auto;
  }
  
  .call-to-action {
    background: #ccc;
    position: absolute;
    max-width: 475px;
    min-height: 135px;
    text-align: center;
    padding: 15px;
    top: 75px;
    left: 0;
    right: 0;
    margin: 0 auto;
    z-index: 5;
  }
  
  h2 {
    color: #807862;
    font-size: 26px;
    line-height: 1;
    margin-bottom: 5px;
  }
  
  p {
    font-size: 13px;
  }
  
  .banner-controls {
    width: 100%;
    text-align: center;
    position: absolute;
    bottom: 0;
    z-index: 5;
  }
  
  ul {
    display: inline-block;
    background-color: rgba(0, 0, 0, 0.5);
    height: 27px;
    line-height: 27px;
    width: 107px;
    margin: 0 auto;
    padding: 0;
    border-radius: 5px 5px 0 0;
  }
  
  .bullet {
    display: inline-block;
    font-size: 38px;
  }
  
  .bullet a {
    text-decoration: none;
    color: #fff;
  }
  
  .bullet a.current {
    color: yellow;
  }
  
  #banner-image {
    background: url(https://unsplash.it/1000/465?image=1) no-repeat;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;body&gt;
    &lt;div id="rotating-banner"&gt;
      &lt;div class="call-to-action"&gt;
        &lt;h2&gt;Headline to go in This Area Right Here.&lt;/h2&gt;
  
        &lt;p&gt;Lorem ipsum dolor sit amet, inceptos lorem adipiscing lacus massa donec egestas, mauris ligula hendrerit dignissim, turpis mauris, in quam voluptatibus, vel at velit vulputate elit sollicitudin ligula.&lt;/p&gt;
      &lt;/div&gt;
  
      &lt;div class="banner-controls"&gt;
        &lt;ul&gt;
          &lt;li class="bullet"&gt;&lt;a id="banner-one" href="#"&gt;&amp;bull;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="bullet"&gt;&lt;a id="banner-two" href="#"&gt;&amp;bull;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="bullet"&gt;&lt;a id="banner-three" href="#"&gt;&amp;bull;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="bullet"&gt;&lt;a id="banner-four" href="#"&gt;&amp;bull;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="bullet"&gt;&lt;a id="banner-five" href="#"&gt;&amp;bull;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
  
      &lt;div id="banner-image"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>