ios移动端点击事件延迟300ms

来源:互联网 发布:淘宝收获地址怎么改 编辑:程序博客网 时间:2024/05/10 19:26

一、tap.js解决方案

  1. <script src="tap.js"></script>  
  2.   
  3. <div id="container">  
  4.   <button id="button-1">Click event</button>  
  5.   <button id="button-2">Tap event</button>  
  6. </div>  
  7.   
  8. <div id="output"></div>  
  9.   
  10. <script>  
  11.   var container = document.getElementById('container')  
  12.   var button1 = document.getElementById('button-1');  
  13.   var button2 = document.getElementById('button-2');  
  14.   var output = document.getElementById('output');  
  15.   
  16.   var tap = new Tap(container);  
  17.   
  18.   button1.addEventListener('click', callback, false);  
  19.   button2.addEventListener('tap', callback, false);  
  20.   
  21.   function callback (e) {  
  22.       e.preventDefault();  
  23.       var p = document.createElement('p');  
  24.       p.textContent = 'event: ' + e.type;  
  25.       output.insertBefore(p, output.firstChild);  
  26.   }  
  27. </script>  
二、fastclick.js解决方法

  1. <script type="application/javascript">  
  2.         window.addEventListener('load', function () {  
  3.             FastClick.attach(document.body);  
  4.         }, false);  
  5.         function xian() {  
  6.      
  7.             $(".fu").show().hide(350);  
  8.         }  
  9.     </script>  

原创粉丝点击