好长时间不做网页了,今天老板说要做一个展示的demo,让这个demo 自动的播放
用js做了一个滚屏播放的代码
<script type="text/javascript"> var done = true; var speed = 4 //设置速度 var currentpos = 0, alt = 1, curpos1 = 0, curpos2 = -1 function initialize() { startit() } function scrollwindow() { if (done) { if (document.all) temp = document.body.scrollTop else temp = window.pageYOffset if (alt == 0) alt = 1 else alt = 0 if (alt == 0) curpos1 = temp else curpos2 = temp if (curpos1 != curpos2) { if (document.all) currentpos = document.body.scrollTop + speed else currentpos = window.pageYOffset + speed window.scroll(0, currentpos) } else { currentpos = 0 window.scroll(0, currentpos) } } } function startit() { setInterval("scrollwindow()", 1000) } function setDone(f) { if (f == 0) { done = false; } if (f == 1) { done = true; } } window.onload = initialize </script>
在上面的这段代码中,我有添加了一个点击停止播放的函数function setDone(f),这个函数可以加到按钮上来控制是否自动播放
例如:
<span style="font-size: 10pt; color: white;" onclick="setDone(1)">自动 </span>
时间: 2024-12-10 09:40:36