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. 表单:checkbox、radio样式(用图片换掉默认样式)

    checkbox.radio样式(用图片换掉默认样式) <!doctype html> <html> <head> <meta charset="u ...

  2. OpenACC 简单的直方图

    ▶ 简单的直方图,强调原子操作的使用 ● 代码 #include <stdio.h> #include <stdlib.h> #include <openacc.h> ...

  3. jpa 多对多

    entity   Item package entity; import java.util.HashSet; import java.util.Set; import javax.persisten ...

  4. 1.urlencoder和urldecoder的使用

    今天传url的时候乱码了.先说情形,url中有searchText=中文的情形,后台new String(searchText.getBytes(ISO-8859-1),"gbk" ...

  5. jquery 的 $.extend 和 $.fn.extend

    $.extend({ add:function(a,b){return a+b;}, bad:function(a,b){return a-b;} }); $.fn.extend({ loading: ...

  6. java ee7 软件安装和环境配置

    1. java ee sdk 最新版下载地址 Java EE软件开发包(Software Development Kit, SDK) http://www.oracle.com/technetwork ...

  7. Spring Boot实践——Mybatis分页插件PageHelper的使用

    出自:https://blog.csdn.net/csdn_huzeliang/article/details/79350425 在springboot中使用PageHelper插件有两种较为相似的方 ...

  8. Mongodb 安装 和 启动

    教程:http://www.mongodb.org.cn/tutorial/59.html 下载 >wget https://fastdl.mongodb.org/linux/mongodb-l ...

  9. <!-- str.startsWith('胡') 检查一个 字符串中是否有某字符 返回true false -->& vh 属性

    1.<!-- str.startsWith('胡')  检查一个 字符串中是否有某字符 返回true false --> 2. vh 分享到选择其它项   复制本页链接 版本:CSS3 补 ...

  10. 使用ngxtop实时监控nginx

    Ngxtop实时解析nginx访问日志,并且将处理结果输出到终端,功能类似于系统命令top,所以这个软件起名ngxtop.有了ngxtop,你可以实时了解到当前nginx的访问状况,再也不需要tail ...