summaryrefslogtreecommitdiff
path: root/pong.html
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2020-09-20 09:26:58 -0700
committerlouie <lshprung@yahoo.com>2020-09-20 09:26:58 -0700
commita8c0d5619ee6d518737628d6c585233d0bba23da (patch)
tree30c13cf2439700c78d51acc9b430cb5fa092f963 /pong.html
First commit
Diffstat (limited to 'pong.html')
-rw-r--r--pong.html15
1 files changed, 15 insertions, 0 deletions
diff --git a/pong.html b/pong.html
new file mode 100644
index 0000000..e0194be
--- /dev/null
+++ b/pong.html
@@ -0,0 +1,15 @@
+<div style='width:650px; height:300px;position:relative; border:1px solid #ccc'>
+ <b style='width:10px; height:10px; background:#000;position:absolute' id=ball></b>
+</div>
+<script>
+ var divH=document.querySelector('div').clientHeight,divW=document.querySelector('div').clientWidth;
+ var b=document.getElementById('ball'),x=divW/2-5,y=divH/2-5,dx=Math.random()*10-5,dy=Math.random()*10-5;
+ setInterval(function(){
+ b.style.left=x+'px'; b.style.top=y+'px';
+ x+=dx;
+ y+=dy;
+ if(y<1 || y>divH-11) dy=-dy;
+ if(x<1 || x>divW-11) dx=-dx;
+ },55);
+
+</script> \ No newline at end of file