网页游戏引擎-半成品
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div style="width: 500px;height: 400px;border: solid 1px;">
<div id="kuaiBut" style="width:20px;height:20px;background-color:green;">
</div>
</div>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var sunDun = 10;
setInterval(function() {
sunDun++;
console.log(sunDun);
moveFun('kuaiBut', 'left', 'top', sunDun);
if (sunDun >= 600) {
sunDun = 0;
}
}, 20)
})
/**
* @param {Object} x 轴
* @param {Object} y 轴
* @param {Object} lengt
*/
function moveFun(id, x, y, lengt) {
let pdWidth = $("#" + id).parent().width();
let pdheight = $("#" + id).parent().height();
console.log(pdWidth + ' - ' + pdheight);
if (y == '' || y == null || y == undefined) {
$("#" + id).css(x, lengt + 'px');
} else {
$("#" + id).css(x, lengt + 'px');
$("#" + id).css(y, lengt + 'px');
}
$("#" + id).css('position', 'absolute');
}
</script>
</html>