JS移动的箭头

<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>

<title>VML - Angle</title>

<STYLE>
 v/:* { BEHAVIOR: url(#default#VML) }
</STYLE>

<SCRIPT Language="JavaScript">

/*
All Files are Designed & Writen by Windy_sk, you can use it freely but ...
YOU MUST KEEP THIS ITEM !
Email: seasonx@163.net
*/

var timer    = null;
var time_unit    = 30;
var A_speed    = 10;
var L_speed    = 15;
var move_x, move_y;

function MoveIt(){
    var the_top     = parseInt(angle.style.top);
    var the_left     = parseInt(angle.style.left);
    angle.style.top  = the_top + move_y;
    angle.style.left = the_left + move_x;
    if(the_top < 0 || the_top > document.body.offsetHeight){
        angle.Rotation    = 180 - angle.Rotation;
        move_y        = -move_y;
        angle.style.top    = the_top<0?0:document.body.offsetHeight + move_y;
    }
    if(the_left < 0 || the_left > document.body.offsetWidth){
        angle.Rotation     = 360 - angle.Rotation;
        move_x         = -move_x;
        angle.style.left = the_left<0?0:document.body.offsetWidth + move_x;
    }
}

document.onkeydown = function(){
    angle.Rotation = angle.Rotation % 360
    if(timer!=null) return;
    var the_angle = Math.PI * angle.Rotation  / 180;
    switch(event.keyCode){
        case 37: //left
            timer = setInterval("angle.Rotation -= A_speed",time_unit);
            break;
        case 39: //right
            timer = setInterval("angle.Rotation += A_speed",time_unit);
            break;
        case 40: //down
            the_angle += Math.PI;
        case 38: //up
            move_y = -Math.floor(L_speed * Math.cos(the_angle));
            move_x = +Math.floor(L_speed * Math.sin(the_angle));
            timer  = setInterval("MoveIt()",time_unit);
            break;
    }
    return;
}

document.onkeyup = function(){
    if(timer!=null) clearInterval(timer);
    timer = null;
}

window.onload = function(){
    setInterval("window.status='Rotation: '+angle.Rotation+';  Top: '+angle.style.top+';  Left: '+angle.style.left",time_unit);
}

</SCRIPT>

</head>
<body scroll="no">

<v:group id="angle" style='position:absolute;top:0;left:0;width:20;height:20;z-index:999' coordorigin="-10,-10" coordsize="20,20">
    <v:shape CoordOrig="-10,-10" CoordSize="20,20" style="width:20;height:20" Title="Hello" FillColor="red" Filled="true" StrokeColor="black" StrokeWeight="1pt">
        <v:Stroke StrokeColor="blue" StrokeWeight="1pt" />
        <v:fill type='gradient' color='blue'/>
        <v:Path v="m 0,-10 l -10,10 l 0,5 l 10,10 x e" />
    </v:shape>
</v:group>

</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值