博主信息
博文 16
粉丝 0
评论 1
访问量 13451
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
飞舞的气泡
浅若夏沫
原创
692人浏览过

照猫画虎做了几遍

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>飞舞的气泡</title>
  8. <style >
  9. #dhk{
  10. background: lightgrey;
  11. width: 600px;
  12. height: 600px;
  13. box-shadow: 0px 5px 5px 3px gray;
  14. }
  15. #btn{
  16. width: 70px;
  17. height: 30px;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div id="dhk"></div>
  23. <input type="button" value="点一点" id="btn">
  24. <script >
  25. var dhk = document.getElementById("dhk");
  26. var colors=['red', 'yellow', 'blue', 'green', 'yellowgreen', '#FF00FF'];
  27. document.getElementById('btn').onclick=function(){
  28. var ball = document.createElement('div');
  29. ball.style.cssText="position:absolute;border-radius:50%;box-shadow: 0px 3px 5px #666";
  30. var kg = Math.floor(Math.random()*70)+30;
  31. ball.style.width=kg+'px';
  32. ball.style.height= kg+'px';
  33. ball.style.backgroundColor=colors[Math.floor(Math.random()*colors.length)];
  34. dhk.appendChild(ball);
  35. var top = dhk.clientHeight/2 - ball.offsetHeight/2;
  36. var left = dhk.clientWidth/2 - ball.offsetWidth/2;
  37. ball.style.left=left+"px";
  38. ball.style.top=top+"px";
  39. var x=Math.floor(Math.random()*10)+1;
  40. var y=Math.floor(Math.random()*10)+1;
  41. setInterval(function() {
  42. left+=x;
  43. top+=y;
  44. if(left < dhk.offsetLeft || left > (dhk.offsetLeft+dhk.offsetWidth-ball.offsetWidth)) {
  45. x = -x;
  46. }
  47. if(top < dhk.offsetTop || top > (dhk.offsetTop+dhk.offsetHeight-ball.offsetHeight-3)) {
  48. y = -y;
  49. }
  50. ball.style.left=left+"px";
  51. ball.style.top=top+"px";
  52. }, 40);
  53. }
  54. </script>
  55. </body>
  56. </html>

批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学