背景:
我的网站使用magento开源电子商务解决方案,在顶部(头部)有一个购物车图标。在桌面上,当用户将鼠标悬停在该图标上时,它会显示购物车中的内容(物品)。但是单击该图标,它会将用户带到购物车页面。
我想要:
我想要只针对触摸设备具有能力,即当用户单击该图标时,它应仅显示内容,但当双击该图标时,它应将其带到购物车页面。
HTML代码:
<div id="mini-cart" class="dropdown is-not-empty">
<!-- This below div is always visible and on tap of this or either of it's any elements, required behaviour is expected -->
<div class="dropdown-toggle cover" title="View Bag">
<div class="feature-icon-hover">
<a href="example.com/checkout/cart/" title="Shopping Bag">
<span class="first close-to-text icon i-cart-wb force-no-bg-color"> </span>
<div class="hide-below-960">My Bag</div>
</a>
<div class="label amount">
<a href="example.com/checkout/cart/" title="Shopping Bag">(1)</a>
</div>
<a class="summary" href="example.com/checkout/cart/" title="Shopping Bag">
<span class="subtotal">
<span class="price">$28</span>
</span>
</a>
<span class="caret"> </span>
</div> <!-- end: dropdown-toggle > div -->
</div> <!-- end: dropdown-toggle -->
<!-- This one is invisible by default, and needs to be shown on single tap -->
<div class="dropdown-menu left-hand" style="display: none;">
<!-- All THE CONTENT GOES HERE -->
</div>
</div>
我已经尝试过的内容:
jQuery(function($){
/* Code to detect the user agent, if mobile device then execute the code*/
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
// on single touch
$("#mini-cart .dropdown-toggle").on('click', 'a', function(e){
e.preventDefault();
$("#mini-cart .dropdown-menu").show();
});
// on double touch
$("#mini-cart .feature-icon-hover").find('a').dblclick(function(e){
location.href = '/checkout/cart';
//alert('dblclick');
});
}
});
这段代码可以阻止单击事件的默认行为,但是不会显示内容div,并且在双击时也没有任何作用。顺便说一下,我正在三星Galaxy上测试它,不确定这是否是一个正确的测试设备,并且使用的是JQUERY插件(不是jquery mobile)。
false;
。否则,浏览器将执行您的代码,然后执行其默认操作。 - Chris S.