JavaScript定时器和进度条案例
2016-03-13 19:02
645 查看
Javascript中的定时器
window对象下面的方法 window.setInterval() interval 间隔 setInterval 建立时间间隔
1.setInterval("function",time) 重复执行某项操作。
时间单位是毫秒
2.setTimeout 运用在延迟一段时间,再进行某项操作。
setTimeout("function",time),setTimeout不会重复
clearTimeout(对象) 清除已设置的setTimeout对象
clearInterval(对象) 清除已设置的setInterval对象
<script language="JavaScript" type="text/javascript">
<!--
function hello(){
alert("hello");
}
window.setTimeout(hello,5000);
//-->
window.setTimeout("hello()",5000);
btnReset.onclick=function(){
seed=0;
}
style.width,offsetWidth
style.width 后面加px 而offsetwidth不加px
console.log() // 控制台日志输出!!!
window对象下面的方法 window.setInterval() interval 间隔 setInterval 建立时间间隔
1.setInterval("function",time) 重复执行某项操作。
时间单位是毫秒
2.setTimeout 运用在延迟一段时间,再进行某项操作。
setTimeout("function",time),setTimeout不会重复
clearTimeout(对象) 清除已设置的setTimeout对象
clearInterval(对象) 清除已设置的setInterval对象
<script language="JavaScript" type="text/javascript">
<!--
function hello(){
alert("hello");
}
window.setTimeout(hello,5000);
//-->
window.setTimeout("hello()",5000);
btnReset.onclick=function(){
seed=0;
}
style.width,offsetWidth
style.width 后面加px 而offsetwidth不加px
console.log() // 控制台日志输出!!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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"> #a1 { margin-top:100px; margin-left:30px; background-color:white; border:solid black 1px; width:1004px; height:54px; } #a2 { margin-top:2px; margin-left:2px; background-color:red; width:0px; height:50px; } </style> <script type="text/javascript" src="2.js"></script> </head> <body onload="start();"> <div id="a1"> <div id="a2"> </div> </div> </body> </html>
// JavaScript Document function show() { if(document.getElementById("a2").offsetWidth<1000) { document.getElementById("a2").style.width= document.getElementById("a2").offsetWidth+30+"px"; console.log(document.getElementById("a2").offsetWidth); } else { document.getElementById("a2").style.width=1000+"px"; stop(); console.log(document.getElementById("a2").offsetWidth); } } var time; function start() { time=window.setInterval("show()",50); } function stop() { clearInterval(time); }
相关文章推荐
- javascript DOM对象
- js
- JavaScript
- 遇到问题-----JS中设置window.location.href跳转无效
- 遇到问题-----JS中设置window.location.href跳转无效
- javascript中的BOM与DOM、JS核心
- 关于javascript的一些内容
- JavaScript学习(三)——利用javascript访问XML文件
- JavaScript之闭包就是个子公司
- jsjl_for_ubuntu12.04
- [置顶] extjs mvc分层代码
- js基础回顾-对象数组篇
- JavaScript实现样式表的简单切换
- JS基础
- 浅谈javascript函数节流
- js 正在表达式 总结
- 使用javascript为网页增加夜间模式
- 深入理解javascript之this
- JSON与XML的区别比较(转)
- Angular Js 控制器