定时器的使用
来源:互联网 发布:java汽车租赁源码 编辑:程序博客网 时间:2024/06/18 11:52
定时器的打开
//间隔持续型setInterval(show,1000);//延时一次型setTimeout(show,1000);定时器的关闭
oBtn1.onclick=function (){Timer = setInterval(function (){alert('a');},1000);}oBtn2.onclick=function(){clearInterval(Timer);}定时器的应用
数码时钟,Date对象的使用
function toDou(n){if(n<10){return '0'+n;}if(n>10){return ''+n;}}window.onload=function(){var aImg = document.getElementsByTagName('img');function Timer(){var oDate = new Date();var str = toDou(oDate.getHours()) + toDou(oDate.getMinutes()) + toDou(oDate.getSeconds());for(var i=0;i<aImg.length;i++){aImg[i].src='img/'+str.charAt(i)+'.png';}}setInterval(Timer,1000);Timer();}
延时提示框 (QQ资料),简化代码
window.onload=function(){oDiv1 = document.getElementById('div1');oDiv2 = document.getElementById('div2');oDiv2.onmouseover=oDiv1.onmouseover=function(){clearTimeout(timer);oDiv2.style.display='block';};oDiv2.onmouseout=oDiv1.onmouseout=function(){timer = setTimeout(function(){oDiv2.style.display='none';},1000)};};无缝滚动基础
window.onload=function (){var oDiv = document.getElementById('div1');var oUl = oDiv.getElementsByTagName('ul')[0];var aLi = oUl.getElementsByTagName('li');var speed =-2;//UL里面的内容加一倍oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';//定时器功能,当UL的内容走到一半的时候再把它扯回来function move(){if(oUl.offsetLeft<-oUl.offsetWidth/2){oUl.style.left='0';}if(oUl.offsetLeft>0){oUl.style.left=-oUl.offsetWidth/2+'px';}oUl.style.left=oUl.offsetLeft+speed+'px';}//使用定时器var Timer = setInterval(move,10);//鼠标进入滚动停止oDiv.onmouseover=function(){clearInterval(Timer);}////鼠标离开滚动开始oDiv.onmouseout=function(){Timer =setInterval(move,10);}//向左滚动document.getElementsByTagName('a')[0].onclick=function(){ speed = -2;};//向右滚动document.getElementsByTagName('a')[1].onclick=function(){speed = 2;};};
阅读全文
0 0
- 定时器的使用
- C#定时器的使用
- C#定时器的使用
- java定时器的使用
- 内核定时器的使用
- 定时器的使用
- linux定时器的使用
- linux定时器的使用
- linux定时器的使用
- linux定时器的使用
- 定时器的使用
- C#定时器的使用
- 内核定时器的使用
- 使用glib的定时器
- Linux定时器的使用
- linux定时器的使用
- 定时器的使用
- timer 定时器的使用
- Per tile sequence quality
- pbc的使用(Windows)
- 模板方法模式
- Client端连接Linux服务器慢问题及解决
- Unity3D -- 性能优化(1)(官方教程The Profiler window翻译官方教程The Profiler window翻译)
- 定时器的使用
- PHP设置SESSION时间
- 中科院计算所范意兴专访: 深度文本匹配工具 MatchZoo 背后的个中细节
- CS231n课后作业讲解第一讲(含代码实现) | 公开课
- 简单的成果(求优化一下)
- 如果样本的标签不保证非常准确怎么办?| 社区问答
- 观察者模式
- 乐动商城隐私政策
- 谷歌开源 TFGAN,让训练和评估 GAN 变得更加简单