title: Create own slider using jQuery
body: <p>Here, I want to create image slider using animate event.
  But when I clicked one time image not replace when I click second time image replace.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var $j = jQuery.noConflict();
  var i = 1;
  $(document).ready(function() {
    $('button').click(function() {
      setInterval(function() {
        var img = "&lt;img src='images/img" + i + ".jpg' /&gt;";
        var $lefty = $j('.image').html(img);
        $lefty.animate({
          left: parseInt($lefty.css('left'), 10) == 0 ? -$lefty.outerWidth() : 0
        }, function() {
          var $marginLefty = $j('.image').html(img);
          $marginLefty.animate({
            marginLeft: parseInt($marginLefty.css('marginLeft'), 10) == 0 ?
              $marginLefty.outerWidth() : 0
          });
        });
        if (i == 4)
          i = 0;
        i++;
      }, 1000);
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code> .slide .inner {
     left: 60px;
     bottom: 0;
   }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;script src="jquery-1.11.2.min.js"&gt;&lt;/script&gt;
    &lt;link href="style.css" type="text/css" rel="stylesheet" /&gt;
    &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
    &lt;div id="slidebottom" class="slide"&gt;
      &lt;button&gt;slide it&lt;/button&gt;
      &lt;div class="inner"&gt;
        &lt;img id="img" src="images/audi_r8_in_snow-1280x720.jpg" /&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>It work when click event perform two times.
  but I want single time performance that image will change.
  Thank you.</p>