开发者

Scrolling vertical text in 2 different divs

开发者 https://www.devze.com 2022-12-17 01:31 出处:网络
I want to scroll 2 divs when I start the page. I add to the onload the events, but it stops here: var cross_marquee=document.getElementById(marque)

I want to scroll 2 divs when I start the page. I add to the onload the events, but it stops here:

var cross_marquee=document.getElementById(marque)
cross_marquee.style.top=0

Can someone help me?

The code is:

var delayb4scroll=2000
var marqueespeed=1
var pauseit=0

var copy开发者_Go百科speed=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")


You're overwriting the onload event.

Create a function that initializes both marquees:


window.onload = function(e)
{
  initializemarquee('wtvmarquee', 'wtmarqueecontainer');
  initializemarquee("wtvmarqueeDiv2", "wtmarqueecontainerDiv2");
}

Additionally, shouldn't be cross_marquee.style.top="0px" ?


Just found another code and modified it to my situation, and its working :) Tks for the help joel ;)

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消