扫码关注官方订阅号
代码如下:
HTML5 class
class
学习是最好的投资!
你的代码的问题很简单,就是几个语法错误,仔细检查下浏览器的报错再发出来啊
包括不限于:
缺{和多}同时存在
function后面没有()
修正的:
<!DOCTYPE html> <html> <head> <title>HTML5</title> <meta charset="UTF-8"> <style type="text/css"> * { margin: 0; padding: 0; } .wrap { position: relative; width: 700px; height: 500px; margin: 0 auto; border: 2px solid #999; } .wrap p { position: absolute; left: 0; top: 0; width: 90px; height: 90px; background-color: #fcf; line-height: 90px; text-align: center; border-radius: 5px; } </style> </head> <body> <p class="wrap" id="outer"> <p class="box" id="inner"> class </p> </p> <script> var outerbox = document.getElementById("outer"), innerbox = document.getElementById("inner"), posX = 20, posY = 60, moveX = true, moveY = true, timer = null; function move() { if (moveX) { posX++; } else { posX--; } if (posX <= 0) { moveX = true; } if (posX >= outerbox.clientWidth - innerbox.offsetWidth) { moveX = false; } if (moveY) { posY++; } else { posY--; } if (posY <= 0) { moveY = true; } if (posY >= outerbox.clientHeight - innerbox.offsetHeight) { moveY = false; } innerbox.style.left = posX + "px"; innerbox.style.top = posY + "px"; } move(); var timer = setInterval(move, 16); </script> </body> </html>
PS: 帮你改了你问题中的源码的排版,建议去了解下markdown语法: http://segmentfault.com/markdown
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
你的代码的问题很简单,就是几个语法错误,仔细检查下浏览器的报错再发出来啊
包括不限于:
缺{和多}同时存在
function后面没有()
修正的:
PS: 帮你改了你问题中的源码的排版,建议去了解下markdown语法: http://segmentfault.com/markdown