通过fastclick源码分析彻底解决tap“点透”(11)


     </style>
 </head>
 <body>
     <div>
     </div>
     <div>
         <div>
             <input type="text" />
         </div>
     </div>
     <script type="text/javascript">
         var el = null;
         function getEvent(el, e, type) {
             e = e.changedTouches[0];
             var event = document.createEvent('MouseEvents');
             event.initMouseEvent(type, true, true, window, 1, e.screenX, e.screenY, e.clientX, e.clientY, false, false, false, false, 0, null);
             event.forwardedTouchEvent = true;
             return event;
         }
         list.addEventListener('touchstart', function (e) {
             var firstTouch = e.touches[0]
             el = firstTouch.target;
             t1 = e.timeStamp;
         })
         list.addEventListener('touchend', function (e) {
             e.preventDefault();
             var event = getEvent(el, e, 'click');
             el.dispatchEvent(event);
         })
         var list = document.getElementById('list');
         list.addEventListener('click', function (e) {
             list.style.display = 'none';
             setTimeout(function () {
                 list.style.display = '';
             }, 1000);
         })
     </script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/155.html