exportconstgetQueryByName=(name)=>{const query =newURLSearchParams(location.search)returndecodeURIComponent(query.get(name))}// url: https://medium.com/?name=fatfish&age=100const name =getQueryByName('name')// fatfishconst age =getQueryByName('age')// 100const gender =getQueryByName('gender')// null
5. 平滑滚动到页面顶部
exportconstscrollToTop=()=>{const c = document.documentElement.scrollTop || document.body.scrollTop
if(c >0){
window.requestAnimationFrame(scrollToTop)
window.scrollTo(0, c - c /8)}}
6. 进入和退出全屏
// Enter full screenexportconstfullScreen=()=>{let el = document.documentElement
let rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen
//typeof rfs != "undefined" && rfsif(rfs){rfs.call(el)}elseif(typeof window.ActiveXObject !=="undefined"){let wscript =newActiveXObject("WScript.Shell")if(wscript !=null){
wscript.SendKeys("{F11}")}}}// Exit full screenexportconstexitScreen=()=>{let el = document
let cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen
//typeof cfs != "undefined" && cfsif(cfs){cfs.call(el)}elseif(typeof window.ActiveXObject !=="undefined"){let wscript =newActiveXObject("WScript.Shell")if(wscript !=null){
wscript.SendKeys("{F11}")}}}