茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    Javascript實現(xiàn)蘋果懸浮虛擬按鈕
    來源:易賢網(wǎng) 閱讀:1522 次 日期:2016-07-08 14:04:54
    溫馨提示:易賢網(wǎng)小編為您整理了“Javascript實現(xiàn)蘋果懸浮虛擬按鈕”,方便廣大網(wǎng)友查閱!

    本文給大家分享的是使用javascript實現(xiàn)仿制蘋果的懸浮虛擬按鈕的代碼,非常的簡單,給大家一個思路,大家可以根據(jù)自己的情況自由擴展。

    直接引入代碼到頁面即可

    代碼有部分冗余的地方,有興趣的小伙伴可也自己修改

    如果有什么BUG 記得評論 告訴我哦

    web-touch.js

    var new_element_N=document.createElement("style"); 

      new_element_N.innerHTML = '#drager {' +

        '   position: fixed;' +

        '   width: 35px;' +

        '   height: 35px;' +

        '   background-color: rgba(0, 0, 0, 0.2);' +

        '   z-index: 10000;' +

        '   cursor: pointer;' +

        '   top: 0px;' +

        '   left: 0px;' +

        '   border-radius: 30%;' +

        '   padding: 6px;' +

        ' }' +

        ' ' +

        ' #drager>div {' +

        '   border-radius: 50%;' +

        '   width: 100%;' +

        '   height: 100%;' +

        '   background-color: rgba(0, 0, 0, 0.3);' +

        '   transition: all 0.2s;' +

        '  -webkit-transition: all 0.2s;' +

        '  -moz-transition: all 0.2s;' +

        '  -o-transition: all 0.2s;' +

        ' }' +

        ' #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="100px";

      new_element_N.style.left="100px";

      new_element_N.innerHTML = ' <div></div>' ;

      document.body.appendChild(new_element_N);

      // 

      // 

        var posX;

        var posY;   

        var screenWidth =document.documentElement.clientWidth;

        var screenHeight = document.documentElement.clientHeight;  

        var fdiv = document.getElementById("drager"); 

        fdiv.onmousedown=function(e)

        { 

          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()//釋放時自動貼到最近位置

        {

          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="0px";

              }

            }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))+"px";

              } 

            }

          }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="0px";

              }

            }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))+"px";

              } 

            }

          } 

        }

        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){//窗口改變適應(yīng)超出的部分

             fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px";

          }  

          if( (parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth))>screenWidth){//窗口改變適應(yīng)超出的部分

             fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px";

          }  

          document.onmouseup.apply()

        };

        fdiv.addEventListener('touchstart', fdiv.onmousedown, false);  

        fdiv.addEventListener('touchmove', function(event) {

                // 如果這個元素的位置內(nèi)只有一個手指的話

                if (event.targetTouches.length == 1) {

                   event.preventDefault();// 阻止瀏覽器默認(rèn)事件,重要 

                  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', document.onmouseup , false);       

        fdiv.ondblclick=function(){//雙擊事件可能在手機端瀏覽器會與網(wǎng)頁縮放事件沖突

          alert("發(fā)揮你們的想象力吧");

        }

    html

    <!doctype html>

    <html >

    <head>

      <meta charset="UTF-8">

      <title>Document</title>

    </head>

    <body>

    </body>

    <script src="web-touch.js" type="text/javascript"></script>

    </html>

    演示圖

    名單

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機網(wǎng)站地址:Javascript實現(xiàn)蘋果懸浮虛擬按鈕
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)