当前位置:网站首页>Web game engine

Web game engine

2022-07-04 17:15:00 The fifth brother of the Wang family

Web game engine - Partially Prepared Products

Sample code :

<!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  Axis 
		 * @param {Object} y  Axis 
		 * @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>

原网站

版权声明
本文为[The fifth brother of the Wang family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041517448333.html