国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > HTML > 正文

html5彈跳球示例代碼

2020-03-24 16:14:46
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

彈跳球使用html5實(shí)現(xiàn),不必驚訝,使用html5完全可以實(shí)現(xiàn),具體的截圖及代碼如下,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助

復(fù)制代碼代碼如下:



<html>

<head>

<meta charset=utf-8>

<title>跳跳球</title>

<script>

//box

var box_x=0;

var box_y=0;

var box_width=300;

var box_height=300;

//注意:定位球采用球的中心

var ball_x=10;

var ball_y=10;

var ball_radius=10;

var ball_vx=5;

var ball_vy=3;

var box_bound_left=box_x+ball_radius;

var box_bound_right=box_x+box_width-ball_radius;

var box_bound_top=box_y+ball_radius;

var box_bound_bottom=box_y+box_height-ball_radius;

//ball

//context

var ctx;

function init()

{

ctx=document.getElementById('canvas').getContext('2d');

ctx.lineWidth=ball_radius;

ctx.fillStyle="rgb(200,0,50)";

move_ball();

setInterval(move_ball,100);//note

}

function move_ball()

{

ctx.clearRect(box_x,box_y,box_width,box_height);

move_and_check();

ctx.beginPath();

ctx.arc(ball_x,ball_y,ball_radius,0,Math.PI*2,true);

ctx.fill();

ctx.strokeRect(box_x,box_y,box_width,box_height);

}

function move_and_check()

{

var cur_ball_x=ball_x+ball_vx;

var cur_ball_y=ball_y+ball_vy;

if(cur_ball_x<box_bound_left)

{

ball_vx=-ball_vx;

cur_ball_x=box_bound_left;

}

if(cur_ball_x>box_bound_right)

{

ball_vx=-ball_vx;

cur_ball_x=box_bound_right;

}

if(cur_ball_y<box_bound_top)

{

ball_vy=-ball_vy;

cur_ball_y=box_bound_top;

}

if(cur_ball_y>box_bound_bottom)

{

ball_vy=-ball_vy;

cur_ball_y=box_bound_bottom;

}

ball_x=cur_ball_x;

ball_y=cur_ball_y;

}

</script>

</head>

<body onLoad="init()">

<canvas id="canvas" width="400" height="400"/>

</body>

</html>

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 两当县| 洛隆县| 柘城县| 班戈县| 富裕县| 同仁县| 吉木萨尔县| 龙陵县| 都昌县| 皋兰县| 巴彦县| 三门峡市| 柘荣县| 商城县| 共和县| 灵山县| 璧山县| 儋州市| 虞城县| 甘洛县| 石门县| 博客| 壤塘县| 宜丰县| 黎平县| 景谷| 乌拉特前旗| 南通市| 泰安市| 阳西县| 晋州市| 抚州市| 望奎县| 原阳县| 丹阳市| 宣威市| 南漳县| 宁陕县| 衡水市| 新建县| 始兴县|