var timeout = 0; var timeId = 0; var type = 1;//1左边 2右边 var ismove = false; var isdown = false; var startTime = 0; var endTime =0; var new_element_N=document.createElement("style"); new_element_N.innerHTML = '#drager {' + ' position: fixed;' + ' width: 50px;' + ' height: 50px;' + ' background-color: rgba(0, 0, 0, 0.5);' + //' background:url(https://cdn.iwantalipstick.com/gameicon2/CrazyKnife.png);'+ ' z-index: 10000;' + ' cursor: pointer;' + ' top: 0px;' + ' left: 0px;' + ' -moz-background-size:100% 100%; ' + ' background-size:100% 100%;'+ ' border-radius: 10px;border: 3px solid #ffffff;'+ ' }' + '#back_btn{' + 'position: fixed;' + 'z-index: 10000;' + 'width: 50px;' + 'height: 50px;' + 'top:20px;' + 'left:20px;' + 'background:url(img/back.png);' + '-moz-background-size:100% 100%;' + 'background-size:100% 100%;' + 'display:none;' + '}' + ' #drager:hover>div{' + ' background-color: rgba(0, 0, 0, 0.6);' + ' } '; document.body.appendChild(new_element_N); new_element_N=document.createElement('div'); new_element_N.setAttribute("id","drager"); new_element_N.style.top="300px";//初始放在屏幕右下角 if(type == 1) { new_element_N.style.left= "10px"; } else { new_element_N.style.left= (document.documentElement.clientWidth-60) + "px"; } var back_element = document.createElement('div'); back_element.setAttribute("id","back_btn"); document.body.appendChild(back_element); back_element.addEventListener('click', ()=>{ location.reload(); } , false); new_element_N.style.display = "none"; var cur_type = 1; var cur_num = 0; //begin("CrazyKnife,4096,Knife,AceMan,AirHockey3D","mi_bs_new"); var platform; var appid; function begin(ids,_platform) { platform = _platform; back_element.style.display = "block"; new_element_N.style.display = "block"; var ids_arr = ids.split(","); new_element_N.style.background = "url(//cdn.iwantalipstick.com/gameicon2/" + ids_arr[cur_num] + ".png) no-repeat"; new_element_N.style.backgroundSize = "100% 100%"; appid = ids_arr[cur_num]; cur_num++; setInterval(()=>{ if(cur_type == 1) { new_element_N.style.opacity = 0.2; cur_type = 2; } else { new_element_N.style.opacity = 1; cur_type = 1; } },300); setInterval(()=>{ //https://cdn.iwantalipstick.com/gameicon2/ if(cur_num >= ids_arr.length) { cur_num = 0; } new_element_N.style.background = "url(//cdn.iwantalipstick.com/gameicon2/"+ids_arr[cur_num]+".png) no-repeat"; new_element_N.style.backgroundSize = "100% 100%"; appid = ids_arr[cur_num]; cur_num++; },5000); } new_element_N.innerHTML = '
' ; document.body.appendChild(new_element_N); beginHit(); // // var posX; var posY; var screenWidth =document.documentElement.clientWidth; var screenHeight = document.documentElement.clientHeight; var fdiv = document.getElementById("drager"); fdiv.onmousedown=function(e) { event.stopPropagation(); isdown = true; clearHit(); startTime = new Date().getTime(); ismove = false; screenWidth =document.documentElement.clientWidth; screenHeight = document.documentElement.clientHeight; if(!e){ e = window.event; } //IE posX = e.clientX - parseInt(fdiv.style.left); posY = e.clientY - parseInt(fdiv.style.top); document.onmousemove = mousemove; } document.onmouseup = function(e)//释放时自动贴到最近位置 { if(!isdown) return; isdown = false; document.onmousemove = null; if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(screenHeight/2)){//在上半部分 if((parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)<=(screenWidth/2)) {//在左半部分 if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)){//靠近上方 fdiv.style.top="0px"; }//else{//靠近左边 fdiv.style.left="10px"; type = 1; beginHit() //} }else{//在右半部分 if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(screenWidth-(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)) ){//靠近上方 fdiv.style.top="0px"; }//else{//靠近右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth)-10)+"px"; type = 2; beginHit() //} } }else{ //下半部分 if((parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)<=(screenWidth/2)) {//在左半部分 if( (screenHeight-(parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2))<=(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)) {//靠近下方 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }//else{//靠近左边 fdiv.style.left="10px"; type = 1; beginHit() //} }else{//在右半部分 if( (screenHeight-(parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2))<=(screenWidth-(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)) ) {//靠近上方 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }//else{//靠近右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth)-10)+"px"; type = 2; beginHit() //} } } } function mousemove(ev) { if(ev==null){ ev = window.event;}//IE if((ev.clientY - posY)<=0){//超过顶部 fdiv.style.top="0px"; }else if((ev.clientY - posY) >(screenHeight-parseInt(fdiv.clientHeight))){//超过底部 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }else{ fdiv.style.top = (ev.clientY - posY) + "px"; } if((ev.clientX- posX)<=0){//超过左边 fdiv.style.left="0px"; }else if((ev.clientX - posX) >(screenWidth-parseInt(fdiv.clientWidth))){//超过右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; }else{ fdiv.style.left = (ev.clientX - posX) + "px"; } // console.log( posX +" "+ fdiv.style.left); } window.onload = window.onresize = function() { //窗口大小改变事件 screenWidth =document.documentElement.clientWidth; screenHeight = document.documentElement.clientHeight; if( (parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight))>screenHeight){//窗口改变适应超出的部分 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; } if( (parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth))>screenWidth){//窗口改变适应超出的部分 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; } document.onmouseup.apply() }; fdiv.addEventListener('touchstart', fdiv.onmousedown, false); fdiv.addEventListener('touchmove', function(event) { ismove = true // 如果这个元素的位置内只有一个手指的话 if (event.targetTouches.length == 1) {      event.preventDefault();// 阻止浏览器默认事件,重要 var touch = event.targetTouches[0]; if((touch.pageY)<=0){//超过顶部 fdiv.style.top="0px"; }else if(touch.pageY>(screenHeight-parseInt(fdiv.clientHeight))){//超过底部 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }else{ fdiv.style.top = (touch.pageY-parseInt(fdiv.clientHeight)/2) + "px"; } if(touch.pageX<=0){//超过左边 fdiv.style.left="0px"; }else if( touch.pageX >(screenWidth-parseInt(fdiv.clientWidth))){//超过右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; }else{ fdiv.style.left = (touch.pageX-parseInt(fdiv.clientWidth)/2) + "px"; } } }, false); fdiv.addEventListener('touchend', mouse_up , false); fdiv.addEventListener('click', mouse_up , false); /* fdiv.onclick=function() { //点击事件可能在手机端浏览器会与网页缩放事件冲突 alert("触发了点击事件!"); } */ function mouse_up(e) { // event.stopPropagation(); endTime = new Date().getTime(); if (endTime - startTime < 500){ clickHome(e); } document.onmouseup(); } var clickTime = 0; function clickHome(e) { if(!e) return; if(!IsPC() && e.type == "mouseup") { return; } if(ismove) return; if (new Date().getTime() - clickTime < 1000 ) { console.log("点击过快") return; } clickTime = new Date().getTime(); //window.location.href="javascript:history.go(-1)"; window.location.href = "//uptapapi.uptap.com/h5Game/?type=Game&platform=" + platform + "&appid="+appid; } function beginHit() { return; if(type == -1)return; clearHit(); timeout = setTimeout("hitBall()",1500); } function clearHit() { clearTimeout(timeout); clearInterval(timeId); } function hitBall() { if(type == -1)return; console.log("--888888888888888888888888--->" + new_element_N.style.left); var step = 1; if(type == 1) { left = 0; } else { left = screenWidth-parseInt(fdiv.clientWidth); } timeId = setInterval(function () { if(type == 1) { if (left > -30) { left -= step; new_element_N.style.left = left + "px"; //console.log(left); } else { clearInterval(timeId); type = -1; } } else { if (left < screenWidth-parseInt(fdiv.clientWidth) + 30) { left += step; new_element_N.style.left = left + "px"; //console.log(left); } else { clearInterval(timeId); type=-1; } } }, 10) } function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; }