var tttt=setTimeout('northsnow()',1000);//执行一次
clearTimeout(tttt);//清除定时
var tttt=setInterval('northsnow()',1000);//循环执行
clearInteval(tttt);//清除定时
定时执行函数 不能有参数 即setTimeout(Dofunction(),1000);
带参数 方式一 : setTimeout("Dofunction(ace)",1000);
方式二 :
setTimeout(_Dofunction(),1000);
function _Dofunction(){
return function (){
Dofunction(ace);
}
}
function Dofunction(ace){
alert(ace);
}

<i></i> <em></em>//斜体
 
<b>注意:</b>加粗

 
文字滚动
方法一。
str+='<div id="buttomdown'+i+'" style="position:absolute;left:'+left+'px;top:'+(top+101)+'px;width:138px;height:24px;background:url(imgs/down.png) no-repeat;text-align:center;z-index: 99;white-space:nowrap;overflow:hidden;"><font id="fontOne'+i+'" class="downfont">'+f_cc_name+'</font><font id="fontTwo'+i+'" class="downfont"></font></div>';
 
var area="";
var con1="";
var con2="";
var scrollData=[];
var adc="";
function getScrollData(){
scrollData.splice(0,scrollData.length);//清空数组
for(var i=0;i<jsonList.length;i++){//获取所有滚动数据
area =document.getElementById('buttomdown'+i);
con1 = document.getElementById('fontOne'+i);
con2 = document.getElementById('fontTwo'+i);
if(con1.offsetWidth>area.offsetWidth){//超过div宽度 开始滚动
scrollData.push(i);
}
}
clearInterval(adc);
adc=setInterval(scrollLeft,50);
}
function scrollLeft(){
for(var i=0;i<scrollData.length;i++){
var a=scrollData[i];
area =document.getElementById('buttomdown'+a);
con1 = document.getElementById('fontOne'+a);
con2 = document.getElementById('fontTwo'+a);
con2.innerHTML=con1.innerHTML;
if(area.scrollLeft>=con1.offsetWidth){
area.scrollLeft=0;
}else{
++area.scrollLeft;
//console.log(area.scrollLeft+"="+con1.offsetWidth);
}
}
}
 
area.onmouseover=function(){//清除定时器 clearInterval(mytimer); } area.onmouseout=function(){//启动定时器 mytimer=setInterval(scrollUp,time); }
方法二。
<marquee></maequee> 标签可以实现滚动
 
js 获取字符串长度 (http://www.jb51.net/article/48202.htm
把双字节的替换成两个单字节的然后再获得长度 
复制代码代码如下:
getBLen = function(str) {
  if (str == null) return 0;
  if (typeof str != "string"){
    str += "";
  }
  return str.replace(/[^\x00-\xff]/g,"01").length;
}
 
var len = getBLen(f_cc_name);//大于div宽度的滚动
if(len*14>206){//字节数*字体大小>div宽度*2
str+='<div id="buttomdown'+i+'" style="position:absolute;left:'+left+'px;top:'+(top+118)+'px;width:103px;height:20px;background:url(imgs/down.png) no-repeat;text-align:center;z-index: 99;white-space:nowrap;overflow:hidden;"><marquee direction=left behavior=scroll loop=-1 scrollamount=2 ><font id="fontOne'+i+'" class="downfont">'+f_cc_name+'</font></marquee></div>';
}else{
str+='<div id="buttomdown'+i+'" style="position:absolute;left:'+left+'px;top:'+(top+118)+'px;width:103px;height:20px;background:url(imgs/down.png) no-repeat;text-align:center;z-index: 99;white-space:nowrap;overflow:hidden;"><font id="fontOne'+i+'" class="downfont">'+f_cc_name+'</font></div>';
}
 

setTimeout setInterval 详解的更多相关文章

  1. setTimeOut和setInterval详解

    setTimeout和setInterval的语法相同.它们都有两个参数,一个是将要执行的代码字符串,还有一个是以毫秒为单位的时间间隔,当过了那个时间段之后就将执行那段代码.不过这两个函数还是有区别的 ...

  2. Javascript异步编程之setTimeout与setInterval详解分析(一)

    Javascript异步编程之setTimeout与setInterval 在谈到异步编程时,本人最主要会从以下三个方面来总结异步编程(注意:特别解释:是总结,本人也是菜鸟,所以总结不好的,请各位大牛 ...

  3. 有关定时器setTimeout()、setInterval()详解

    JavaScript提供定时执行代码的功能,叫做定时器(timer),主要由setTimeout()和setInterval()这两个函数来完成. setTimeout() setTimeout函数用 ...

  4. js setInterval详解

    [自己总结]: 语法  setInterval(code,interval) ①可以有第三个参数,第三个参数作为第一个参数(函数)的参数 ②第一个参数是函数,有三种形式: 1.传函数名,不用加引号,也 ...

  5. 定时器详解和应用、js加载阻塞、css加载阻塞

    1.setTimeout().setInterval()详解和应用 1.1 详解: setTimeout.setInterval执行时机 1.2 存在问题: setInterval重复定时器可能存在的 ...

  6. 关于setTimeout()你所不知道的地方,详解setTimeout()

    关于setTimeout()你所不知道的地方,详解setTimeout() 前言:看了这篇文章,1.注意setTimeout引用的是全部变量还是局部变量了,当直接调用外部函数方法时,实际上函数内部的变 ...

  7. 如何通过setTimeout理解JS运行机制详解

    setTimeout()函数:用来指定某个函数或某段代码在多少毫秒之后执行.它返回一个整数,表示定时器timer的编号,可以用来取消该定时器. 例子 ? 1 2 3 4 5 console.log(1 ...

  8. JS中this关键字详解

    本文主要解释在JS里面this关键字的指向问题(在浏览器环境下). 阅读此文章,还需要心平气和的阅读完,相信一定会有所收获,我也会不定期的发布,分享一些文章,共同学习 首先,必须搞清楚在JS里面,函数 ...

  9. JS 中 this 关键字详解

    本文主要解释在JS里面this关键字的指向问题(在浏览器环境下). 首先,必须搞清楚在JS里面,函数的几种调用方式: 普通函数调用 作为方法来调用 作为构造函数来调用 使用apply/call方法来调 ...

随机推荐

  1. 1. Two Sum + 15. 3 Sum + 16. 3 Sum Closest + 18. 4Sum + 167. Two Sum II - Input array is sorted + 454. 4Sum II + 653. Two Sum IV - Input is a BST

    ▶ 问题:给定一个数组 nums 及一个目标值 target,求数组中是否存在 n 项的和恰好等于目标值 ▶ 第 1题,n = 2,要求返回解 ● 代码,160 ms,穷举法,时间复杂度 O(n2), ...

  2. 比较完整的URL验证

    转自:http://wuchaorang.2008.blog.163.com/blog/static/4889185220135279223253/ function IsURL(str_url){v ...

  3. 使用sqldeveloper连接服务器端数据库

  4. python之函数嵌套与闭包

    一:函数的嵌套:在函数内部在定义一个函数,一层套一层 def father(name): print("from father %s" %name) def son(): prin ...

  5. Python中的操作符重载

    运算符重载是指在方法中拦截内置的操作----当类的实例出现在内置操作中,Python会自动调用自定义的办法,并且返回自定义方法的操作结果.     类可以重载python的操作符 操作符重载使我们的对 ...

  6. InitComponent的使用

    网页中的数据,有些是不在网页上改变的,像一些个人信息,比如:头像,当前用户名,友情链接等等,每次请求该页面都要重新加载,这样很消耗服务器资源,会降低服务器的性能,这个时候我们可以把这些不变的信息,统一 ...

  7. Technology, globalisation and the squeeze on good jobs

    Technology, globalisation and the squeeze on good jobs技术与全球化冲击好工作“Highest stock market EVER! Jobs ar ...

  8. Java 枚举那点事

    目录 最近有需求,想存自定义的枚举值,比如 HOTLINE("Hotline") 我想存 Hotline 于是研究了一下Java的枚举问题 如下数据库的Entity (贫血模型哈) ...

  9. PHP与apache配置

    在apache 的安装路径中找到 \conf\httpd.conf文件 在 LoadModule最后面添加如下代码: PHPIniDir "D:\PHP"LoadModule ph ...

  10. Scriptable Object

    [Scriptable Object] ScriptableObject 是一个可继承的Class,适用于存储大数据的情形.  Consider for example that you have m ...