分享
 
 
 

Javascirpt打造“互动指针”特效

王朝java/jsp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

一个很不错的效果,用键盘的箭头键控制一个漂亮的箭头!也许能给你启发,做出一款有趣的小游戏呢

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

<head>

<title>Interactive Arrow</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 ArrowStyle(type,color,color2,focus){

if(color == "") color = "white";

if(color2 == "") color2 = "white";

this.type = type;

this.color = color;

this.color2 = color2;

this.focus = focus;

}

var style_list = new Array();

style_list[style_list.length] = new ArrowStyle("gradient","blue","","");

style_list[style_list.length] = new ArrowStyle("gradient","","blue","");

style_list[style_list.length] = new ArrowStyle("gradient","blue","red","");

style_list[style_list.length] = new ArrowStyle("gradient","red","blue","");

style_list[style_list.length] = new ArrowStyle("gradient","blue","red","50%");

style_list[style_list.length] = new ArrowStyle("gradient","red","blue","-50%");

style_list[style_list.length] = new ArrowStyle("gradientradial","","blue","");

style_list[style_list.length] = new ArrowStyle("gradientradial","blue","","");

style_list[style_list.length] = new ArrowStyle("gradientradial","red","blue","");

style_list[style_list.length] = new ArrowStyle("gradientradial","blue","red","");

style_list[style_list.length] = new ArrowStyle("gradientradial","red","blue","50%");

style_list[style_list.length] = new ArrowStyle("gradientradial","blue","red","-50%");

function ChangeStyle(){

if(style_list.length == 0) return;

var the_style = style_list[GetRandomNum(1,style_list.length) - 1];

fill.type = the_style.type;

fill.color = the_style.color;

fill.color2 = the_style.color2;

fill.focus = the_style.focus;

}

/*

function ChangeStyle(){

fill.type = GetRandomNum(0,1)?"gradient":"gradientradial";

fill.color = GetRandomdColor();

fill.color2 = GetRandomdColor();

fill.focus = GetRandomNum(0,1)?"+":"-" + GetRandomNum(0,100).toString() + "%";

}

function GetRandomdColor(){

var result = "";

var hex = new Array(6);

hex[0] = "FF";

hex[1] = "CC";

hex[2] = "99";

hex[3] = "66";

hex[4] = "33";

hex[5] = "00";

for(var i=0;i<3;i++){

result += hex[GetRandomNum(0,5)];

}

return result;

}

*/

function GetRandomNum(Min,Max){

var Range = Max - Min;

var Rand = Math.random();

return(Min + Math.round(Rand * Range));

}

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;

}

document.onclick = function(){

ChangeStyle();

}

document.onmousewheel = function(){

if (event.wheelDelta >= 120){

angle.style.width = Math.ceil(parseInt(angle.style.width) * 1.1);

angle.style.height = Math.ceil(parseInt(angle.style.height) * 1.1);

}else if (event.wheelDelta <= -120){

angle.style.width = Math.ceil(parseInt(angle.style.width) * 0.9);

angle.style.height = Math.ceil(parseInt(angle.style.height) * 0.9);

}

return;

}

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="Interactive Arrow" FillColor="red" Filled="true" StrokeColor="black" StrokeWeight="1pt">

<v:Stroke StrokeColor="black" StrokeWeight="1pt" />

<v:fill id=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>

<style>

a:hover{color:#036;}

</style>

<script language="javascript">

var rate = 20;

var obj;

var act = 0;

var elmH = 0;

var elmS = 128;

var elmV = 255;

var clrOrg;

var TimerID;

if (navigator.appName.indexOf("Microsoft",0) != -1 && parseInt(navigator.appVersion) >= 4) {

Browser = true;

} else {

Browser = false;

}

if (Browser) {

document.onmouseover = doRainbowAnchor;

document.onmouseout = stopRainbowAnchor;

}

function doRainbow()

{

if (Browser && act != 1) {

act = 1;

obj = event.srcElement;

clrOrg = obj.style.color;

TimerID = setInterval("ChangeColor()",100);

}

}

function stopRainbow()

{

if (Browser && act != 0) {

obj.style.color = clrOrg;

clearInterval(TimerID);

act = 0;

}

}

function doRainbowAnchor()

{

if (Browser && act != 1) {

obj = event.srcElement;

while (obj.tagName != 'A' && obj.tagName != 'BODY') {

obj = obj.parentElement;

if (obj.tagName == 'A' || obj.tagName == 'BODY')

break;

}

if (obj.tagName == 'A' && obj.href != '') {

act = 1;

clrOrg = obj.style.color;

TimerID = setInterval("ChangeColor()",100);

}

}

}

function stopRainbowAnchor()

{

if (Browser && act != 0) {

if (obj.tagName == 'A') {

obj.style.color = clrOrg;

clearInterval(TimerID

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有