持續更新javascript
MP3 不容許啓動AudioContextphp
The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page pc端打開chrome瀏覽器,新建頁籤,地址欄輸入 chrome://flags/#autoplay-policy 選擇 No user gesture is required 以後重啓瀏覽器便可,chrome瀏覽器更新版本後的新增的安全策略。
判斷iOS系統版本號css
if(navigator.userAgent.match(/iphone/i)){ var verinfo = navigator.userAgent.match(/os [\d._]*/gi); version = (verinfo+"").replace(/[^0-9|_.]/ig,"").replace(/_/ig,".");//獲取具體的系統版本號 console.log(version); }
【M】iOS12微信輸入法鍵盤彈起H5頁面沒法還原html
//判斷ios系統 var u=navigator.userAgent; if(u.indexOf('iPhone')>-1){ var flag; $('body').on('focus','input',function(){ flag=false; }); $('body').on('blur','input',function(){ flag=true; setTimeout(function(){ if(flag==false){ return false; }else{ document.body.scrollTop=document.body.scrollTop; } //防止在多個input間切換時作過多操做 },0) }); }
【M】微信JSSDK分享至朋友圈成功後不回調問題前端
微信分享至朋友圈後回調的方法內若使用ajax,需配置爲同步(async:false),不然會出現不回調的狀況。 var share_opts = { title : '首屆接梗王大賽,這些00後都不懂的梗,你能接上來多少?', desc : '1分鐘,挑戰10道題,包含電影、動漫、遊戲...答對有獎!快來挑戰!>>', img : '../images/share.jpg', url : location.href.split('#')[0], key : '', successCallback: function(){ $.ajax({ type: 'post', dataType:"json", async : false, url: "common/share.php", data:{'url':location.href.split('#')[0]}, success: function(data){ if(data.status==1) { alert("分享成功,可再次挑戰!"); window.location.href=window.location.href; } } }); } }; $(function(){ weixin_jssdk_ops.init(share_opts); });
【swiper】4.0滾輪沒法滾動java
參數 3.0 mousewheelControl : true,//開啓鼠標切換 4.0 mousewheel : true,//開啓鼠標切換 解決方式 //從底層庫類註釋執行代碼 //搜索 // B.handle // //註釋 // if (!s.mouseEntered && !a.releaseOnEdges) // return !0;
【M】rem逐幀動畫抖動解決方案ios
https://aotu.io/notes/2017/08/14/fix-sprite-anim/
【M】audio標籤在蘋果機上沒法自動播放web
<!-- music --> <audio controls="controls" loop="loop" autoplay="autoplay" id="musicAudio"> <source src="images/bg_music.mp3" type="audio/mpeg"/> </audio> <script> var bgAudio = document.getElementById('musicAudio'); document.addEventListener('WeixinJSBridgeReady',function(){ bgAudio.play(); }, false); </script>
動態改變微信titleajax
var $body = $('body'); document.title = '五班老同窗(35)'; var $iframe = $("<iframe style='display:none;' src='/favicon.ico'></iframe>"); $iframe.on('load',function() { setTimeout(function() { $iframe.off('load').remove(); }, 0); }).appendTo($body);
判斷是不是微信環境chrome
function isWeChat(){ this.ua = navigator.userAgent.toLowerCase(); return this.ua.match(/MicroMessenger/i) == 'micromessenger'?true:false; }
解決a標籤雙擊出現藍色背景
a,button,input,optgroup,select,textarea, div { -webkit-tap-highlight-color:rgba(0,0,0,0); /*去掉a、input和button點擊時的藍色外邊框和灰色半透明背景*/ }
判斷瀏覽器低版本插入HTML提示函數
if(!!window.ActiveXObject || "ActiveXObject" in window){ $('body').append('<div style="width:100%;height:50px;background:#fff;color:#000;border-bottom:1px solid #fff;text-align:center;line-height:50px;border-top:1px solid #cfcfcf;font-size:16px;position:fixed;bottom:0;z-index: 9999">您使用的瀏覽器版本太低,可能會影響到您瀏覽本頁面,建議升級您的瀏覽器: <a href="http://www.google.cn/chrome/browser/desktop/" style="padding:15px; background:#c81331; color:#fff;" target="_black">谷歌 Chrome</a></div>').css('padding-bottom','200px'); };
前端引用外鏈須知
//正常外鏈引用 <script type="text/javascript" src="http://x.js"></script> //防止外鏈加載緩慢 加上異步加載 //方法一 -async <script type="text/javascript" src="http://x.js" async></script> 此方法只兼容高版本 //方法二 動態建立JS (function() { var hm = document.createElement("script"); hm.src = "http://x.js"; var s = document.getElementsByTagName("body")[0]; s.appendChild(hm); })();
監聽video播放或暫停事件
var myVideo=document.getElementById('video'); myVideo.addEventListener('play',function(){ //播放執行 }); myVideo.addEventListener('pause',function(){ //暫停執行 })
UC瀏覽器會出現背景圖可點的狀況
bug說明 # 當背景圖採用img的方式時,在UC瀏覽器下(其餘瀏覽器不會),會出現點擊背景圖,瀏覽器會當作一張圖片解析,彈出背景圖。 解決方案 # 給img標籤添加去除瀏覽器默認行爲的點擊事件 # 把img變成background (把圖片變成css中的背景圖) 代碼示例 //html <img src="mobile/images/bg_.png" alt="" onclick="return false">
【PC端】CKobject多個視頻同時播放-其它視頻未關閉
API 文檔 http://www.ckplayer.com/manual/ 線上例子 http://act.leiting.com/wd/201705/pk/pc/index.html 代碼 if(CKobject.getObjectById('ckplayer_a1')){ CKobject.getObjectById('ckplayer_a1').videoPause(); } if(CKobject.getObjectById('ckplayer_a2').playOrPause){ CKobject.getObjectById('ckplayer_a2').playOrPause(); }
【移動端】上傳附件
蘋果手機目前只支持訪問圖片和視頻格式的文件上傳,暫不支持其餘格式的文件 安卓手機支持多種格式上傳,但存在部分機型不支持或是失效 建議:上傳除圖片之外的格式文件仍是在PC上完成比較好 //錯誤示範 在瀏覽器模擬iphone的時候是各類文件均可以上傳(以真機爲主) //正確示範 iphone目前只支持訪問圖片和視頻格式的文件上傳(真機測試結果)
【移動端】使用margin排版問題
margin 排位會有問題,最好使用 定位 【移動端】使用margin排版問題
【移動端】點擊事件沒法觸發
JS建立DOM的時候,本來的事件沒法綁定、事件委託失敗, //錯誤示範 $('.picture').on('click',function(){ alert(1) }) //正確示範(是在$('.product ul')下面建立DOM)使用綁定的方式 $('.product ul').on('click','.picture',function(){ alert(1) })
雷霆遊戲console
(function() { this.log = window.console.log; this.log('%cL%ce%ci%cT%ci%cn%cg %cG%ca%cm%ce', 'font-size:30px;color:#32e60b;', 'font-size:30px;color:#64d41b;', 'font-size:30px;color:#97e012;', 'font-size:30px;color:#f9f701;', 'font-size:30px;color:#fe9e00;', 'font-size:30px;color:#d4651b;', 'font-size:30px;color:#5f3b7a;', 'font-size:30px;color:#3d319a;', 'font-size:30px;color:#313eb0;', 'font-size:30px;color:#1f38ac;', 'font-size:30px;color:#0b1479;'); this.log('咱們是XXXXXXX-%c平臺Web前端團隊', 'color:#fd6a7f;font-weight:bold;'); this.log('XXXXXX始終貫徹着-%c爲用戶創造美好體驗', 'color:#fd6a7f'); this.log('加入XXXXXX-%chttp://BAIDU.com/', 'color:#fd6a7f'); this.log('%c', 'padding:30px 140px;line-height:100px;background:url("logo.png") no-repeat;background-size:100% 100%;'); this.log('%c--------', 'color:pink') })();
JS如何判斷是否是iphoneX?
function isIphoneX(){ return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375) }