tags:

views:

153

answers:

2

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 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")
+1  A: 
Joel Alejandro
Hijust tried, but didn't work.Only one div is scrooling, and is faster.. for example, if i remove the first initializemarquee('wtvmarquee', 'wtmarqueecontainer'); it have the right speed, if i insert it, it double the speed for the same div.What is wrong??
Luis
setTimeout('lefttime=setInterval("scrollmarquee()" ,30)', delayb4scroll) - I'm not sure, but I think you're overloading the interval as well...
Joel Alejandro
hmm, I do not know very much javascript, can you help fix it?
Luis
I'm debugging this with Firebug on Firefox 3.6 RC2. You have a scope problem here. Some of the variables referenced at scrollmarquee() are defined as locals on initializemarquee(). In what browser have you tested this script?
Joel Alejandro
Firefox and IE8 , and it works, but only for one div. i want to scroll 2 diferent divs at the same time :S.And i found this code, to scroll one div, and i am trying to put in 2 divs, but its hard :S. so i ask for some help :) Do you know a simple code to scroll 2 divs at the same time on the load of the page??
Luis
If you correct the scope problem I mentioned earlier (i.e. cross_marquee === undefined on scrollmarquee) this script should be working. Anyway, have you tried this? -> http://www.webmasterworld.com/javascript/3551205.htm
Joel Alejandro
+1  A: 

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>
Luis
Glad I could help ;)
Joel Alejandro