Link to home
Start Free TrialLog in
Avatar of kmurphychi
kmurphychi

asked on

Javascript repeat and reduce space between items in Marquee scroller

Hi.  I need to get this javascript marquee scroller to repeat and also for there not to be such a big pause between the news items.  Any help would be greatly appreciated. Below is the code and you can see it at http://www.samfaziomusic.com.
<script type="text/javascript">
	var dhtmlgoodies_marqueeSteps = <?php echo $steps1 ?>;	// Higher = Faster, Lower = slower and more smoothly
	var dhtmlgoodies_marqueeSpeed = <?php echo $speed1 ?>;	// Lower value = Faster
	var dhtmlgoodies_marqueeStopOnMouseOver = <?php echo $onmouse1 ?>;	// Make the marquee stop moving when user moves his mouse over it
	var dhtmlgoodies_marqueePosition = '<?php echo $position1 ?>';	// "top" or "bottom"

	/* Don't change anything below here */
	var dhtmlgoodies_marqueeObj;
	var dhtmlgoodies_marqueeTextObj;
	var dhtmlgoodies_marqueeTmpStep;
	var dhtmlgoodies_marqueeTextObjects = new Array();
	var dhtmlgoodies_marqueeHiddenSpans = new Array();

	var dhtmlgoodies_marqueeIndex = 0;
	function repositionMarquee(e,timeout)
	{
		if(document.all)e=event;
		if(dhtmlgoodies_marqueePosition.toLowerCase()=='top'){
			dhtmlgoodies_marqueeObj.style.top = '0px';
		}else{
			dhtmlgoodies_marqueeObj.style.bottom = '-1px';
		}
		if(document.all && !timeout)setTimeout('repositionMarquee(false,true)',500)
	}
	function marqueeMove()
	{
		var leftPos = dhtmlgoodies_marqueeTextObj.offsetLeft;
		leftPos = leftPos - dhtmlgoodies_marqueeTmpStep;
		var rightEdge = leftPos + dhtmlgoodies_marqueeHiddenSpans[dhtmlgoodies_marqueeIndex].offsetLeft;
		if(rightEdge<0){
			leftPos = document.documentElement.offsetWidth;
			dhtmlgoodies_marqueeTextObj.style.display='none';
			dhtmlgoodies_marqueeIndex++;
			if(dhtmlgoodies_marqueeIndex>=dhtmlgoodies_marqueeTextObjects.length)dhtmlgoodies_marqueeIndex = 0;
			dhtmlgoodies_marqueeTextObj = dhtmlgoodies_marqueeTextObjects[dhtmlgoodies_marqueeIndex];
			dhtmlgoodies_marqueeTextObj.style.display='block';

		}
		dhtmlgoodies_marqueeTextObj.style.left = leftPos + 'px';

	}

	function stopMarqueeMove()
	{
		if(dhtmlgoodies_marqueeStopOnMouseOver)dhtmlgoodies_marqueeTmpStep = 0;
	}
	function resumeMarqueeMove()
	{
		dhtmlgoodies_marqueeTmpStep = dhtmlgoodies_marqueeSteps;
	}
	function initMarquee()
	{
		dhtmlgoodies_marqueeObj = document.getElementById('dhtmlgoodies_marquee');

		var spans = dhtmlgoodies_marqueeObj.getElementsByTagName('DIV');
		for(var no=0;no<spans.length;no++){
			if(spans[no].className=='textObj'){
				if(!dhtmlgoodies_marqueeTextObj){
					dhtmlgoodies_marqueeTextObj = spans[no];
					spans[no].style.display='block';
				}else spans[no].style.display='none';
				dhtmlgoodies_marqueeTextObjects.push(spans[no]);
				var hiddenSpan = document.createElement('SPAN');
				hiddenSpan.innerHTML = ' '
				spans[no].appendChild(hiddenSpan);
				dhtmlgoodies_marqueeHiddenSpans.push(hiddenSpan);

			}
		}
		if(dhtmlgoodies_marqueePosition.toLowerCase()=='top'){
			dhtmlgoodies_marqueeObj.style.top = '0px';
		}else{
			if(document.all){
				dhtmlgoodies_marqueeObj.style.bottom = '0px';
			}else{
				dhtmlgoodies_marqueeObj.style.bottom = '-1px';
			}
		}




		dhtmlgoodies_marqueeObj.style.display='block';
		dhtmlgoodies_marqueeTextObj.style.left = document.documentElement.offsetWidth + 'px';
		dhtmlgoodies_marqueeObj.onmouseover = stopMarqueeMove;
		dhtmlgoodies_marqueeObj.onmouseout = resumeMarqueeMove;
		if(document.all)window.onscroll = repositionMarquee; else dhtmlgoodies_marqueeObj.style.position = 'fixed';

		dhtmlgoodies_marqueeObj.style.display='block';
		dhtmlgoodies_marqueeTmpStep = dhtmlgoodies_marqueeSteps;

		setInterval('marqueeMove()',dhtmlgoodies_marqueeSpeed);
	}
</script>

Open in new window

Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

would be useful to see step and speed
Avatar of kmurphychi
kmurphychi

ASKER

Thanks for your response.  The step is 2 and speed of scroller is 28.  It's a joomla module.
I am getting

<div style="display: none; left: -614px;" class="textObj"><span class="highlighted">News:</span>&nbsp;&nbsp;&nbsp;<a href="http://www.samfaziomusic.com/index.php?option=com_eventlist&view=eventlist&Itemid=12">NEW PERFORMANCES JUST ADDED!  CHECK OUT PERFORMANCES PAGES</a><span> </span></div>
      <div style="display: block; left: 1533px;"

but actually in FF on Mac, each item simply appear to the right when the previous has scrolled off to the left
It's the 1533px that I am having trouble changing I guess.  I now see that it does repeat after all so I don't need to change that, but can't seem to figure out how to make it so that it doesn't wait until all the text has moved off before it shows the next line of text.
This is the CSS associated with it that I can find.  


	html{
		height:100%;
		font-family: Segoe UI,Tahoma,Verdana,Arial;
	}
	body{
		margin:0px;
		padding:0px;
		text-align:center;
		height:100%;
	}
	#mainContainer{
		width:400px;
		border-left:1px solid #000;
		border-right:1px solid #000;
		margin:0 auto;
		height:100%;
		text-align:left;
	}
	#topRow{

	}
	#mainContent{
		padding-left:10px;
		padding-right:10px;
	}

	#dhtmlgoodies_marquee{
		/* general marquee layout*/
		padding-top:3px;
		height:25px;
		background-color: #000;
		color: #EC7524;


		/* End general marquee layout */


		position:absolute;
		left:0px;
		z-index:1000;
		bottom:0px;
		display:none;
		width:100%;
		overflow:hidden;
	}
	body > div#dhtmlgoodies_marquee{	/* Firefox rule */
		position:fixed;
	}
	#dhtmlgoodies_marquee a{
	color:#EC7524;
}
	#dhtmlgoodies_marquee .textObj{	/* Layout for the marquee text */
		position:absolute;
		color: #FFF;
		font-weight:bold;
		white-space:nowrap;
		font-family: Segoe UI,Tahoma,Verdana,Arial;
        font-size:15px;
	}
	/* Just some layout classes used in this example script */
	.highlighted{
		color:#EC7524;	// Red color
	}
	.greenText{
		color:#EC7524;	// Green color
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you! Thank you! Thank you!
<|:-)