title: Best way to change CSS Background Image on hover
body: <p>I have a Full-Screen Background image that I need to swap out for other images when hovering over a div. I'm doing this with jQuery - the problem is there's a fairly significant load time. </p>
  
  <p>Is there a way to structure this so that the image appears near-instantaneously on the first hover? Code I have below: </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>$("#hover-bg-2").mouseover(function() {
    $("#container").css("background", "url(/assets/image-2.jpg)");
    $("#container").css("-webkit-background-size", "cover");
    $("#container").css("-moz-background-size", "cover");
    $("#container").css("-o-background-size", "cover");
    $("#container").css("background-size", "cover");
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#container {
    width: 100vw;
    height: 100vh;
    
    /* ORIGINAL IMAGE BEFORE CHANGE */
    background: url(/assets/image-1.jpg) no-repeat center center fixed;
    
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
  }</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;div id="container"&gt;
    &lt;div class="bg-hover"&gt;
      &lt;div id="hover-bg-2" style="cursor: pointer;"&gt;
        &lt;p&gt;BG 2&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>