感觉自己最近也是石乐志了
什么都不记得了 但是,我会学的很快的
今天就是上次说了 那个方块 用JS 写哎 真的是很简单的东西 觉得自己最近 真的是诚惶诚恐
一个方块 从 左上 到右下 移动
就是用的是定时器 setinterval 连续的 然后 获取他的当前位置 判断 之后 加10px
下面是代码:
HTML,css我就 不写了 CSS上就是定位了一下
JS:
算了 写上吧 我怕自己忘 了
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link href="mirrorPage.css" rel="stylesheet" />
<script src="mirrorPage.js"></script>
</head>
<body>
<div id="content">
<div id="face1"></div>
</div>
</body>
</html>
CSS:
body {
margin:0;
padding:0;
}
#content {
width:100px;
height:100px;
margin:100px auto;
position:relative;
background-color:#ff0000;
}
#face1 {
position:absolute;
width:10px;
height:10px;
top:0%;
left:0%;
background-color:#ffd800;
}
window.onload = function () {
var dd = document.getElementById("face1");
var time = setInterval(function () {
if (dd.offsetLeft == 90) {
clearInterval(time);
}
else {
dd.style.left = dd.offsetLeft + 10 + "px";
dd.style.top = dd.offsetTop + 10 + "px";
}
}, 100);
}
行的 问题都解决了 一身轻松啊。 下来就是自己学写一些小代码了。
哎,本想把 我的那些垃圾代码都弄到GITHUB上,搞了半天GITHUB 放弃了
一个人的。。。