熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET Web中的鼠標自動移動

2013-11-13 09:51:49  來源: .NET編程 

  其實只是一個模擬思路是這樣的讓鼠標消失再用一個跟鼠標一樣的圖片跟隨鼠標移動這樣我們就可以控制這個圖片的移動了囧~

  怎樣讓鼠標消失呢就是做一個高寬px的透明cur文件並把其設置為鼠標光標就行了囧囧~~~
 

  這裡是我們需要的兩個素材

  透明cur

  鼠標圖片

  ok現在思路和素材都有了我們就可以編碼實現了

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>
<html xmlns=>
    <head>
        <style type=text/css>
            body{
                cursor:url()auto;
            }
        </style>
        <script type=text/javascript>
            function $I(id){
                return typeof(id)==string?documentgetElementById(id):id;
            };

  var isMoving=false;
            windowonload=function(){
                $I(arrow)styleposition=absolute;
                $I(arrow)stylezIndex=;
               
                documentbodyonmousemove=function(e){
                    e=e||event;
                    if(!isMoving){
                        $I(arrow)styleleft=eclientX+documentdocumentElementscrollLeft++px;
                        $I(arrow)styletop=eclientY+documentdocumentElementscrollTop++px;
                    }
                };
                documentoncontextmenu=function(e){
                    e=e||event;
                    if(isMoving){
                        ereturnValue=false;
                    }
                };
                $I(btn)onclick=function(){
                    alert(lalala~~~~);
                };
               
                windowsetInterval(function(){
                    if(!isMoving){
                        move(parseInt($I(arrow)styleleft)parseInt($I(arrow)styletop)
                             parseInt($I(btn)styleleft)+$I(btn)offsetWidth/
                             parseInt($I(btn)styletop)+$I(btn)offsetHeight/)
                       
                    }
                });
            }
           
            function getAngle(startXstartYendXendY)
            {
                var angle;
                var tanx;
                if(endXstartX!=){
                    tanx=Mathabs(endYstartY)/Mathabs(endXstartX);
                }else{
                    return +(endYstartY>?:);
                }
                angle=Mathatan(tanx)//MathPI*;
           
                if(endXstartX< && endYstartY<=){
                    angle=angle;
                }
                if(endXstartX< && endYstartY>){
                    angle+=;
                }
                if(endXstartX>= && endYstartY>){
                    angle=angle;
                }
                return angle;
            };
           
            function move(startXstartYendXendY){
                var currentDistance=;
                var currentX=startX;
                var currentY=startY;
                var angle=getAngle(startXstartYendXendY);
                var speed=;
                var intervalId=windowsetInterval(function(){
                    if(Mathabs(parseInt($I(arrow)styleleft)endX)>speed
                    || Mathabs(parseInt($I(arrow)styletop)endY)>speed){
                        var newXnewY;
                        var xAngle=angle*(*MathPI/);
                        var xDirection=Mathabs(s(xAngle))/s(xAngle);
                        var yDirection=Mathabs(Mathsin(xAngle))/Mathsin(xAngle);
               
                        if(Mathabs(Mathtan(xAngle))<=){
                            var deltaX=Mathabs(speed*s(xAngle))*xDirection;
                            newX=currentX+deltaX;
                            newY=(newXstartX)*Mathtan(xAngle)+startY;
                        }
                        else{
                            var deltaY=Mathabs(speed*Mathsin(xAngle))*yDirection;
                            newY=currentYdeltaY;
                            newX=(newYstartY)/Mathtan(xAngle)+startX;
                        }
                        currentX=newX;
                        currentY=newY;
                        $I(arrow)styleleft=currentX+px;
                        $I(arrow)styletop=currentY+px;
                        isMoving=true;
                    }
                    else{
                        windowclearInterval(intervalId);

  isMoving=false;
                        $I(btn)click();
                        $I(btn)focus();
                    }
                });
            }

  </script>
    </head>
    <body>
        <input type=button id=btn value=I am a Button/>
        <div ></div>
        <img id=arrow src=>
    </body>
</html>


From:http://tw.wingwit.com/Article/program/net/201311/11781.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.