javascript加速运动
2024-08-25 08:51:36
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
#div1
{
width: 100px;
height: 100px;
background-color: green;
position: absolute;
left:600px;
top: 50px;
}
#div2
{
width:1px;
height:300px;
position:absolute;
background-color:gray;
left:300px;
top:0px;
}
</style>
</head>
<script type="text/javascript">
var timer = null;
function Move() {
var oDiv = document.getElementById("div1");
timer = setInterval(function () {
var speed = (300 - oDiv.offsetLeft) / 10;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
oDiv.style.left = oDiv.offsetLeft + Math.ceil(speed) + "px";
}, 30);
}
</script>
<body>
<input type="button" id="btn" value="开始运动" onclick="Move()" />
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
最新文章
- 数据结构《19》----String容器的三种实现
- 《DSP using MATLAB》示例Example4.4
- 八位彻底改变App Store的iOS开发者
- NOI2010航空管制
- 掌握C++基础
- Android Studio 简介
- Codeforces 219D Choosing Capital for Treeland
- T-SQL语句中中括号([])的用法是什么,什么时候该用
- 基于visual Studio2013解决C语言竞赛题之前言
- 禁用 VS2010 的 vcpkgsrv.exe 运行
- 《Windows驱动开发技术详解》之读写操作
- 微信公众平台快速开发框架 For Core 2.0 beta &ndash;JCSoft.WX.Core 5.2.0 beta发布
- struts2框架学习之第三天
- 英语发音规则---I字母常见发音组合有哪些
- EF连接Sqlserver2014,使用DBGeography时提示无法加载sqlserverspatial.dll
- Django--cookie操作
- Why is my Spring @Autowired field null?
- CSS3动画和JS动画的比较
- Chapter9(顺序容器) --C++Prime笔记
- C语言学习链接