jQuery触摸和滑动

时间:2014-04-21 11:01:29

标签: javascript android jquery touch swipe

我正在为移动设备创建jquery滑块。对于触摸和滑动,我使用的是touchSwipe插件。

当您在空白区域滑动时它工作正常,但是当我在锚链接上滑动时它无法正常工作。

这是我的HTML代码。

<article data-status="loaded" id="deals-most-popular" class="deals-tube deals-populate-region">
  <div class="col-1">
    <ul data-category="most-popular">
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/21486/102/florida-car-rentals-from-tampa-orlando-miami-more"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 15+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Florida</strong> Florida Car Rentals from Tampa, Orlando, Miami &amp; More </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/114021/102/myrtle-beach-hotel-deals-vacation-packages-in-spring-w-extras"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 30+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Myrtle Beach</strong> Myrtle Beach Hotel Deals &amp; Vacation Packages in Spring w/Extras </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/103392/102/fly-round-trip-to-cities-worldwide-on-emirates"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 634+ </em> </span> <span class="deal-text" itemprop="name"> <strong>South America</strong> Fly Round-Trip to Cities Worldwide on Emirates </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/37068/102/rome-florence-venice-7-nts-w-air-train-hotel"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 1665+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Italy</strong> Rome, Florence &amp; Venice: 7 Nts w/Air, Train &amp; Hotel </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/37045/102/athens-istanbul-6-nights-w-flights-hotel"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 1159+ </em> </span> <span class="deal-text" itemprop="name"> <strong>World</strong> Athens &amp; Istanbul: 6 Nights w/Flights &amp; Hotel </span> </a> </li>
    </ul>
  </div>
  <div class="col-1">
    <ul data-category="most-popular">
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/37053/102/london-paris-rome-9-nts-w-air-transfer-hotel"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 1859+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Europe</strong> London, Paris &amp; Rome: 9 Nts w/Air, Transfer &amp; Hotel </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/37063/102/prague-vienna-budapest-7-nts-w-air-hotel"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 1445+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Europe</strong> Prague, Vienna &amp; Budapest: 7 Nts w/Air &amp; Hotel </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/37060/102/barcelona-rome-6-nts-w-air-transfer-hotel"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 1429+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Europe</strong> Barcelona &amp; Rome: 6 Nts w/Air, Transfer &amp; Hotel </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/108188/102/6-nights-at-the-bahamas-paradise-island-all-incl-resort-w-air"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 859+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Bahamas</strong> 6 Nights at the Bahamas Paradise Island All-Incl. Resort w/Air </span> </a> </li>
      <li itemtype="http://schema.org/Offer" itemscope=""> <a target="_blank" itemprop="url" href="http://staging.click.deals.shermanstravel.com/37064/102/barcelona-ibiza-6-nt-package-w-air-hotel"> <span class="deal-price" itemprop="price"> <em> <sup>$</sup> 1245+ </em> </span> <span class="deal-text" itemprop="name"> <strong>Spain</strong> Barcelona &amp; Ibiza 6-Nt Package w/Air &amp; Hotel </span> </a> </li>
    </ul>
  </div>
</article>

脚本

![$(function() {      
      //Enable swiping...
      $("#deals-most-popular").swipe( {
        //Generic swipe handler for all directions
        swipe:function(event, direction, distance, duration, fingerCount) {
          if(direction === "left"){
              $(this).cycle("next");
             // alert('left')
          } else if(direction === "right"){
              $(this).cycle("prev");
              //alert('right')
          }
        },
        //Default is 75px, set to 0 for demo so any distance triggers swipe
         threshold:0
      });
    });][3]

enter image description here

1 个答案:

答案 0 :(得分:0)

默认情况下,锚点(&#34; a&#34;)元素将从滑动中排除(请参阅&#34; excludedElements&#34;属性)。

http://labs.rampinteractive.co.uk/touchSwipe/docs/symbols/%24.fn.swipe.defaults.html

您可以通过将该列表设置为更适合您的需要来进行链接滑动,但是您可能需要处理不执行其本机链接的锚点#34;动作(仅限android?)(可能使用&#34;点击&#34;(以前称为&#34;点击&#34;)处理程序)。

http://labs.rampinteractive.co.uk/touchSwipe/demos/Tap_vs_swipe.html

HTH,

安迪