- 微信双击上移问题
1 var agent = navigator.userAgent.toLowerCase(); //检测是否是ios 2 var iLastTouch = null; //缓存上一次tap的时间 3 if (agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0){ 4 document.body.addEventListener('touchend', function(event) 5 { 6 var iNow = new Date() 7 .getTime(); 8 iLastTouch = iLastTouch || iNow + 1 /** 第一次时将iLastTouch设为当前时间+1 */ ; 9 var delta = iNow - iLastTouch; 10 if (delta < 500 && delta > 0) 11 { 12 event.preventDefault(); 13 return false; 14 } 15 iLastTouch = iNow; 16 }, false); 17 }
- 阻止ios拖拽到底部还能继续拖拽
1 var ScrollFix = function(elem) { 2 // Variables to track inputs 3 4 var startY, startTopScroll; elem = elem || document.querySelector(elem); 5 6 // If there is no 7 8 element, then do nothing 9 10 if(!elem) 11 return; 12 13 // Handle the start of interactions 14 15 elem.addEventListener('touchstart', function(event){ 16 startY = event.touches[0].pageY; 17 startTopScroll = elem.scrollTop; 18 19 if(startTopScroll <= 0) 20 elem.scrollTop = 1; 21 22 if(startTopScroll + elem.offsetHeight >= elem.scrollHeight) 23 elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1; 24 }, false); 25 };
- ios 音乐不能自动播放解决方案
1 function audioAutoPlay(id){ 2 var audio = document.getElementById(id), 3 play = function(){ 4 audio.play(); 5 document.removeEventListener("touchstart",play, false); 6 }; 7 audio.play(); 8 document.addEventListener("WeixinJSBridgeReady", function () { 9 play(); 10 }, false); 11 document.addEventListener('YixinJSBridgeReady', function() { 12 play(); 13 }, false); 14 document.addEventListener("touchstart",play, false); 15 } 16 audioAutoPlay('muc');
***
扫描二维码,关注web全栈开发工程师,获取最新最全的全栈开发内容