setInterval()和clearInterval()是一对很有用的js函数,可以用来重复执行某些功能,利用这个我们可以实现一些很有趣的功能。
scrollTop()函数可以用来实现滚动条一直处于某个位置。
以下是用这三个函数做的一个例子。
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
var _interval;
var i=1;
function showTime()
{
var today = new Date();
$("#msg").append(today.toLocaleString() + "I am Thinking You!\n");
var scrollTop = $("#msg")[0].scrollHeight;
$("#msg").scrollTop(scrollTop);
i++;
if (i>15)
{
clearInterval(_interval);
}
}
$(document).ready(function(){
$("#btnStart").click(function(){
showTime();
_interval = setInterval("showTime()", 1000);
})
$("#btnStop").click(function(){
clearInterval(_interval);
i=0;
})
})
</script>
</head>
<body>
<textarea id="msg" style="width:400px; height: 100px;border: 1px #ccc solid; resize:none;"></textarea><br/>
<button id="btnStart">开始</button>
<button id="btnStop">停止</button>
<script type="text/javascript">
</script>
</body>
</html>
分享到:
相关推荐
在上面的代码中,我们使用了marquees.scrollLeft和marquees.scrollTop这两个属性来控制图片的滚动。ScrollLeft和ScrollTop是HTML元素中的两个属性,用于控制元素的水平和垂直滚动。 ScrollLeft表示元素的水平滚动...
obj.style.top = y + document.body.scrollTop x = x + step*(xin?1:-1) if (x ) { xin = true; x = L} if (x > R){ xin = false; x = R} y = y + step*(yin?1:-1) if (y ) { yin = true; y = T } if (y > B) { yin ...
img1.style.top = yPos + document.body.scrollTop; if (yon) {yPos = yPos + step;} else {yPos = yPos - step;} if (yPos ) {yon = 1;yPos = 0;} if (yPos >= (height - Hoffset)) {yon = 0;yPos...
obj.style.top = y document.documentElement.scrollTop "px"; x = x step*(xin?1:-1) if (x ) { xin = true; x = L} if (x > R){ xin = false; x = R} y = y step*(yin?1:-1) if (y ) { yin = true; y...
function initialize() { timer=setInterval(“scrollwindow()”,10); } function sc(){ clearInterval(timer); } function scrollwindow() { currentpos=document.body.scrollTop; window.scroll(0,...
img.style.top = yPos + document.body.scrollTop; if (yon) { yPos = yPos + step; } else { yPos = yPos - step; } if (yPos ) { yon = 1; yPos = 0; } if (yPos >= (height - Hoffset)) { yon = 0; yPos = ...
浮动广告代码 右下角漂浮代码 [removed] initAd();//载入页面后,调用函数...obj.onmouseover=function(){clearInterval(itl)} obj.onmouseout=function(){itl=setInterval("floatwww_qpsh_com()", delay)} [removed]
document.all.tooltip2.style.pixelTop=event.clientY+document.body.scrollTop+10 document.all.tooltip2.style.visibility="visible" } else if (document.layers){ document.tooltip2.document.nstip.document....
function initialize(){ timer=setInterval(“scrollwindow()”,30);}function sc(){ clearInterval(timer);}function scrollwindow(){ currentpos=document.body.scrollTop; window.scroll(0,++curren
function initialize(){ timer = setInterval(“scrollwindow()”, 1); } function sc(){ clearInterval(timer); } function scrollwindow(){ currentpos = document.body.scrollTop; window.scroll(0, ++...
J()){_=_||setInterval(function(){if(V[N].readyState=="complete")clearInterval(_);U(null,true)},50);return}if($dp.status==0){$dp.status=1;L.el=T;I(L,true)}else return}else if(L.eCont){L.eCont=$dp.$(L....
定时 timer=setInterval("scrollwindow()",delay); clearInterval(timer); UNCODE编码 escape() ,unescape 父对象 obj.parentElement(dhtml) obj.parentNode(dom) 交换表的行 TableID.moveRow(2,1) 替换...
else if (document.layers){clearInterval(currentscroll)document.tooltip2.visibility="hidden"}}function scrolltip(){if (document.tooltip2.document.nstip.left>=-document.tooltip2.document.nstip...
<!... charset=gb2312" /> <title>test</title><br></head><br><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"><br><table height=1000><br><tr><td>dddd</td></tr> </table> </body>...