Javascript 在两个不同的分区中滚动垂直文本
我想在开始页面时滚动2Javascript 在两个不同的分区中滚动垂直文本,javascript,Javascript,我想在开始页面时滚动2divs。我将事件添加到onload中,但仅限于此: var cross_marquee=document.getElementById(marque) cross_marquee.style.top=0 有人能帮我吗 代码是: var delayb4scroll=2000 var marqueespeed=1 var pauseit=0 var copyspeed=marqueespeed var pausespeed=(pauseit==0)? copyspeed:
div
s。我将事件添加到onload中,但仅限于此:
var cross_marquee=document.getElementById(marque)
cross_marquee.style.top=0
有人能帮我吗
代码是:
var delayb4scroll=2000
var marqueespeed=1
var pauseit=0
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''
var actualheightDiv2=''
function scrollmarquee(){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.sty le.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+ "px"
}
function initializemarquee(marque, container){
var cross_marquee=document.getElementById(marque)
cross_marquee.style.top=0
marqueeheight=document.getElementById(container).o ffsetHeight
actualheight=cross_marquee.offsetHeight
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
cross_marquee.style.height=marqueeheight+"px"
cross_marquee.style.overflow="scroll"
return
}
setTimeout('lefttime=setInterval("scrollmarquee()" ,30)', delayb4scroll)
}
window.onload=initializemarquee('wtvmarquee', 'wtmarqueecontainer')
window.onload=initializemarquee("wtvmarqueeDiv2", "wtmarqueecontainerDiv2")
您正在覆盖onload事件 创建一个初始化两个选框的函数:
window.onload=函数(e)
{
初始化为marquee('wtvmarquee','wtmarqueecontainer');
初始化为marquee(“wtvmarqueeDiv2”、“wtmarqueeecontainerdiv2”);
}
另外,不应该是
cross_marquee.style.top=“0px”
?刚刚找到另一个代码并根据我的情况修改它,它的工作:)
谢谢你的帮助,乔尔;)
.滚动框{
/*显示滚动内容的框*/
位置:绝对位置;
顶部:30px;
左:200px;
宽度:180px;
高度:200px;
边框:1px虚线#aaaaa;
溢出:隐藏;
}
.scrollTxt{
/*实际包含我们内容的框*/
字体:普通12px无衬线;
位置:相对位置;
顶部:200px;
}
.scrollBox2{
/*显示滚动内容的框*/
位置:绝对位置;
顶部:300px;
左:200px;
宽度:180px;
高度:200px;
边框:1px虚线#aaaaa;
溢出:隐藏;
}
.TXT2{
/*实际包含我们内容的框*/
字体:普通12px无衬线;
位置:相对位置;
顶部:470px;
}
var scrollSpeed=1;//每帧要更改的像素数
变量scrollDepth=200;//显示框的高度
var scrollHeight=0;//这将保持内容的高度
var scrollDelay=38;//动作之间的延迟。
var scrollPos=scrollDepth;//当前滚动位置
var scrollMov=滚动速度;//用于滚动的停止和启动
var scrollPos2=滚动深度;//当前滚动位置
var scrollMov2=滚动速度;//用于滚动的停止和启动
函数doscorl(){
如果(scrollHeight==0){getHeight();}
scrollPos-=scrollMov;
如果(scrollPos<(0-scrollHeight)){scrollPos=scrollDepth;}
document.getElementById('scrollTxt').style.top=scrollPos+'px';
setTimeout('doscorl();',scrollDelay);
}
函数getHeight(){
scrollHeight=document.getElementById('scrollTxt')。offsetHeight;
}
函数doscorl2(){
如果(scrollHeight==0){getHeight2();}
scrollPos2-=scrollMov2;
如果(scrollPos2<(0-scrollHeight)){scrollPos2=scrollDepth;}
document.getElementById('scrollTxt2').style.top=scrollPos2+'px';
setTimeout('doscorl2();',scrollDelay);
}
函数getHeight2(){
scrollHeight=document.getElementById('scrollTxt2')。offsetHeight;
}
window.onload=函数(e)
{
多斯克罗尔();
Doscoroll2();
}
Hi刚试过,但没用。只有一个潜水艇在偷懒,而且速度更快。。例如,如果我删除了第一个初始值marquee('wtvmarquee','wtmarqueecontainer');它有正确的速度,如果我插入它,它的速度是同一个div的两倍。怎么了?setTimeout('lefttime=setInterval(“scrollmarquee()”,30)),delayb4scroll)-我不确定,但我认为你也在重载间隔…嗯,我不太懂javascript,你能帮我修复吗?我正在用Firefox3.6RC2上的Firebug进行调试。这里有一个范围问题。scrollmarquee()引用的一些变量在initializemarquee()上定义为局部变量。你在哪个浏览器中测试过这个脚本?Firefox和IE8,它可以运行,但只适用于一个div。我想同时滚动两个不同的div:S。我找到了这个代码,滚动一个div,我正试图放入两个div,但是它很难:S。所以我请求一些帮助:)你知道一个简单的代码可以在加载页面时同时滚动2个div吗??
window.onload = function(e)
{
initializemarquee('wtvmarquee', 'wtmarqueecontainer');
initializemarquee("wtvmarqueeDiv2", "wtmarqueecontainerDiv2");
}
<style type="text/css">
.scrollBox {
/* The box displaying the scrolling content */
position: absolute;
top: 30px;
left: 200px;
width: 180px;
height: 200px;
border: 1px dashed #aaaaaa;
overflow: hidden;
}
.scrollTxt {
/* the box that actually contains our content */
font: normal 12px sans-serif;
position: relative;
top: 200px;
}
.scrollBox2 {
/* The box displaying the scrolling content */
position: absolute;
top: 300px;
left: 200px;
width: 180px;
height: 200px;
border: 1px dashed #aaaaaa;
overflow: hidden;
}
.scrollTxt2 {
/* the box that actually contains our content */
font: normal 12px sans-serif;
position: relative;
top: 470px;
}
</style>
<script type="text/javascript">
var scrollSpeed =1; // number of pixels to change every frame
var scrollDepth =200; // height of your display box
var scrollHeight=0; // this will hold the height of your content
var scrollDelay=38; // delay between movements.
var scrollPos=scrollDepth; // current scroll position
var scrollMov=scrollSpeed; // for stop&start of scroll
var scrollPos2=scrollDepth; // current scroll position
var scrollMov2=scrollSpeed; // for stop&start of scroll
function doScroll() {
if(scrollHeight==0) { getHeight(); }
scrollPos-=scrollMov;
if(scrollPos< (0-scrollHeight)) { scrollPos=scrollDepth; }
document.getElementById('scrollTxt').style.top=scrollPos+'px';
setTimeout('doScroll();', scrollDelay);
}
function getHeight() {
scrollHeight=document.getElementById('scrollTxt').offsetHeight;
}
function doScroll2() {
if(scrollHeight==0) { getHeight2(); }
scrollPos2 -= scrollMov2;
if(scrollPos2< (0-scrollHeight)) { scrollPos2=scrollDepth; }
document.getElementById('scrollTxt2').style.top=scrollPos2 +'px';
setTimeout('doScroll2();', scrollDelay);
}
function getHeight2() {
scrollHeight=document.getElementById('scrollTxt2').offsetHeight;
}
window.onload = function(e)
{
doScroll();
doScroll2();
}
</script>