title: Adapt hover animation for iPad with touch events
body: <p>This is my first attempt at developing something with touch events. I have a slider that animates on hover, and the first two slides have links that reveal hidden content on click.   Trying to figure out a way to adapt it so that the content animates on swipe instead of on hover, and still maintain the "on click" for the links within the slides. The site I use has jQuery 1.3.2 with no hope of upgrading so hoping to find something that will work with that old library.</p>
  
  <p>You can see the slider in progress <a href="http://lcoawebservices.com/mariner/slider-hover-swipe-test.html" rel="nofollow noreferrer">here</a>.  I also put it into a fiddle:<a href="http://jsfiddle.net/uqY8E/" rel="nofollow noreferrer">http://jsfiddle.net/uqY8E/</a></p>
  
  <p>Ultimately, what I am trying to achieve is to move the slides (it's OK if the background is static on the iPad) when the user swipes their finger, and if they lift their finger, the animation stops, just like it starts and stops with hover.  I <a href="https://stackoverflow.com/questions/12186892/hover-and-click-event-on-mobile-devices">read this</a> and created an if/else statement so it will still work on hover. The animation won't work on the iPad, but the arrows do not display so I think the if statement is correct.</p>
  
  <p><strong>jQuery</strong>:</p>
  
  <pre><code>            $(document).ready(function() {
          var timer;
  
          if(!!('ontouchstart' in window)){
              $("#nextarrow, #backarrow").hide();
              $(".mid").bind('touchstart', function(){
                  timer = setInterval(function() {swipeLeft();}, 50);
              }, function() {
                  clearInterval(timer);
              });
  
              function swipeLeft() {
                                  if(($(".mid").position().left) &gt;= -1880){
                                  $("#background").stop().animate({
                                      'left': '-=2px'
                                  }, 50);
                                  $(".mid").stop().animate({
                                      'left': '-=20px'
                                  }, 50);
                                  }
                              }
          }
  
          else{
          $("#nextarrow").hover(function() {
                  timer = setInterval(function() {slideLeft();}, 50);
              }, function() {
                  clearInterval(timer);
              });
  
  
          $("#backarrow").hover(function() {
                  timer = setInterval(function() {slideRight();}, 50);
              }, function() {
                  clearInterval(timer);
              });
  
  
  
          function slideLeft() {
              if(($(".mid").position().left) &gt;= -1880){
              $("#background").stop().animate({
                  'left': '-=2px'
              }, 50);
              $(".mid").stop().animate({
                  'left': '-=20px'
              }, 50);
              }
          }
  
          function slideRight() {
              if(($(".mid").position().left) &lt;= -10){
              $("#background").stop().animate({
                  'left': '+=2px'
              }, 50);
              $(".mid").stop().animate({
                  'left': '+=20px'
              }, 50);
              }
          }
  
          }
  
  
          $("#shop-slide1").click(function() {
          $("#shop-slide1-contents").animate({'bottom': '-0px'}, 1000);
          $(".close").click(function() {
          $("#shop-slide1-contents").animate({'bottom': '-525px'}, 1000);
          });
          });
  
          $("#shop-slide2").click(function() {
          $("#shop-slide2-contents").fadeIn('slow');
          $(".close").click(function() {
          $("#shop-slide2-contents").fadeOut('fast');
          });
          });
  
          });
  </code></pre>
  
  <p><strong>HTML</strong>:</p>
  
  <pre><code>            &lt;div id="mask"&gt;
              &lt;div id="nextarrow"&gt;&lt;/div&gt;
              &lt;div id="backarrow"&gt;&lt;/div&gt;
              &lt;div id="background"&gt;&lt;/div&gt;
              &lt;div class="mid"&gt;                   
                                   &lt;div id="slide1" class="slide"&gt;
                                      &lt;p id="shop-slide1" class="shop-link"&gt;+ Shop The Collection&lt;/p&gt;
                                   &lt;/div&gt;
                                   &lt;div id="slide2" class="slide"&gt;
                                      &lt;p id="shop-slide2" class="shop-link" style="color: #fff; font-weight: bold;"&gt;+ I need this&lt;/p&gt;
                                   &lt;/div&gt;
                                   &lt;div id="slide3" class="slide"&gt;&lt;/div&gt;
                                   &lt;div id="slide4" class="slide"&gt;&lt;/div&gt;
                                   &lt;div id="slide5" class="slide"&gt;&lt;/div&gt;
  
  
              &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>Do I need to change the swipeLeft function specifically for the iPad? I copied it from the hover event.  Any help in getting this to work - or suggestions for an alternate way to adapt this for the iPad - are much appreciated.  I am new at this, so lots to learn!</p>