请问javascript每隔多少秒执行一次得函数是什么
展开全部
函数setInterval("语句",时间),语句可以是“alert('ddd');”这样的简单语句,为了完成更多的事情,也可以自己定义一个函数,时间是毫秒为单位的,比如可以是2000,表示两秒重复一次。
例子程序如下:
<DIV ID=dd STYLE="Z-INDEX:1; LEFT:46px; POSITION: absolute; TOP: 124px;" onmouseover="fly_ctrl=false" onmouseout="fly_ctrl=true">
<A HREF="/cai/ymessage.html" title="向你推荐阳光QQ:工作联系的最佳工具"><IMG HEIGHT=32 WIDTH=32 BORDER=0 style="filter:chroma(color=#ffffff)" SRC="/ym.gif"></A></DIV>
<SCRIPT LANGUAGE=JavaScript>
var fly_ctrl=true;
var xPos = 20;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
dd.style.top = yPos;
function changePos() {
if (fly_ctrl==false) return;
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = dd.offsetHeight;
Woffset = dd.offsetWidth;
dd.style.left = xPos + document.body.scrollLeft;
dd.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}
else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}
else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function start() {
dd.visibility = "visible";
interval = setInterval('changePos()', delay);
}
function pause_resume() {
if(pause) {
clearInterval(interval);
pause = false;
}
else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
</SCRIPT>
例子程序如下:
<DIV ID=dd STYLE="Z-INDEX:1; LEFT:46px; POSITION: absolute; TOP: 124px;" onmouseover="fly_ctrl=false" onmouseout="fly_ctrl=true">
<A HREF="/cai/ymessage.html" title="向你推荐阳光QQ:工作联系的最佳工具"><IMG HEIGHT=32 WIDTH=32 BORDER=0 style="filter:chroma(color=#ffffff)" SRC="/ym.gif"></A></DIV>
<SCRIPT LANGUAGE=JavaScript>
var fly_ctrl=true;
var xPos = 20;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
dd.style.top = yPos;
function changePos() {
if (fly_ctrl==false) return;
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = dd.offsetHeight;
Woffset = dd.offsetWidth;
dd.style.left = xPos + document.body.scrollLeft;
dd.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}
else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}
else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function start() {
dd.visibility = "visible";
interval = setInterval('changePos()', delay);
}
function pause_resume() {
if(pause) {
clearInterval(interval);
pause = false;
}
else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
</SCRIPT>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询