【发布时间】:2015-08-30 05:36:54
【问题描述】:
我正在尝试创建一个交互式网络漫画(在 html、css 和 javascript 中),我想在其中触发自动页面以定义的速度从一个点向下滚动到另一个点,以使用多个 jpg 图像制作连续动画.
简单来说,当读者滚动并到达页面的某个(我已经定义的)位置时,页面会自动强制将页面向下滚动到预定义的点。
就像他们在这个网络卡通中所做的那样:http://comic.naver.com/webtoon/detail.nhn?titleId=350217&no=31
我也想触发音效,就像他们在上面提到的链接中所做的那样......
我尝试使用以下脚本完成此操作,但无法控制滚动的开始和停止位置。另外,我还希望它在单个页面加载时只滚动一次。
<SCRIPT language=JavaScript1.2>
//change 1 to another integer to alter the scroll speed. Greater is faster
var speed=1
var currentpos=0,alt=1,curpos1=0,curpos2=-1
function initialize(){
startit()
}
function scrollwindow(){
if (document.all &&
!document.getElementById)
temp=document.body.scrollTop
else
temp=window.pageYOffset
if (alt==0)
alt=2
else
alt=1
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()",50)
}
window.onload=initialize
</SCRIPT>
提前致谢
【问题讨论】:
标签: javascript jquery html css scroll