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. Java-IntegerCache

    Integer类里面有一个私有的静态内部类IntegerCache类加载时,有一段静态块代码,如下 static final int low = -128; static final int high ...

  2. THREE.JS 场景世界坐标和平面二维坐标互转

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  3. 在mfc中picture控件中显示Mat图片<转>

    void ShowMatImgToWnd(CWnd* pWnd, cv::Mat img) { if(img.empty()) return; CRect drect; pWnd->GetCli ...

  4. python之建完model之后操作admin

    1)建完model 之后,运行./manage.py migrate 2)建立管理员:./manage.py createsuperuser 3)输入用户名和命令上提示的信息,在点击网址,输入admi ...

  5. centos多版本python安装pip

    http://www.cnblogs.com/longxiang92/p/5829373.html yum install python-pip 报错 no package python-pip av ...

  6. unity WWW加载进度条

    using UnityEngine; using System.Collections; public class testProgress : MonoBehaviour { void Start ...

  7. How to Pronounce ‘to the’ in a Sentence

    How to Pronounce ‘to the’ in a Sentence Share Tweet Share Tagged With: The Word THE, TO Reduction St ...

  8. Oracle VM VirtualBox做好虚拟硬盘后,如何进一步修改虚拟硬盘的大小

    以管理员身份打开, 命令提示符窗口,然后利用命令cd进入Oracle VM VirtualBox安装目录,如下图: 我进入了Oracle VM VirtualBox安装目录:D:\Program Fi ...

  9. 吴裕雄 实战python编程(3)

    import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com'html = requests.get(url)sp ...

  10. python -m

    影响sys.path python xxx.py python -m xxx.py 这是两种加载py文件的方式:1叫做直接运行2把模块当作脚本来启动 直接启动是把脚本所在的目录放到了sys.path属 ...