PDA

View Full Version : Scroller help



anousht
04-13-2005, 12:10 PM
I've got this great scroller from you guys, but I'd like to add one more function to it. I need each item to pause once it's in the center so that the user can read it before the next item comes in. I know it pauses on mouse-over, but my users aren't that web-savvy, and may not figure that out.
Here's the script I'm talking about.

http://www.dynamicdrive.com/dynamicindex2/cmarquee.htm

thanks in advance.

jscheuer1
04-13-2005, 03:11 PM
I'll take a look at modifying the script. In the meantime, there are two options to take care of your 'problem' that do not require a script modification.

1) On the page where you display the marquee, write just above or below it:
"Move mouse pointer over text to pause" or words to that effect.

2) Set the speed to 1. That should be slow enough for anyone to read it, paused or not.

anousht
04-13-2005, 03:32 PM
Thanks!
I'll suggest that to my client, but I'd love to hear your suggestions after you look at the script, just in case she doesn't go for that.

jscheuer1
04-14-2005, 03:35 AM
Actually, I had looked at the script before but, for a different reason. The person posting wanted to put spaces between the each section of content in the scroller. I suppose you know you can use the named entity non-breaking space:
 to add spaces to the content. This will be required to tweak the script once you apply the code updates I am going to offer in order to get it to pause. First of all this script has a statement:
marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NSWhich although I understand the reasoning behind it, makes no sense to me as, in testing, both NS7.2 and NS4.79 showed no need for this, it just made them one step slower. Remove it and they all go the same speed. Remove it. Now things get a little tricky. Replace this function:
function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"

}
else if (document.layers){
if (ns_marquee.left>(actualwidth*(-1)+8))
ns_marquee.left-=copyspeed
else
ns_marquee.left=parseInt(marqueewidth)+8
}
}with these two functions and one call:
function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else{
clearTimeout(t1);
clearTimeout(t2);
clearTimeout(t3);
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
p=40
strstp();
}
}
else if (document.layers){
if (ns_marquee.left>(actualwidth*(-1)+8))
ns_marquee.left-=copyspeed
else{
clearTimeout(t1);
clearTimeout(t2);
clearTimeout(t3);
ns_marquee.left=parseInt(marqueewidth)+8
p=40
strstp();
}
}
}
function strstp(){
t1=setTimeout("copyspeed=pausespeed",3050-p);
p=0
t2=setTimeout("copyspeed=marqueespeed",6100);
t3=setTimeout("strstp()",6200);
}
strstp()Add this:
var p=0just below:
////NO NEED TO EDIT BELOW THIS LINE////////////Those modifications work well with the demo at speed 2, it looks even better if you add spaces to the content of the demo so that it looks like this:
var marqueecontent='<nobr><font face="Arial">&nbsp;&nbsp;Thank you for visiting <a href="http://www.dynamicdrive.com">Dynamic Drive.</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If you find this script useful, please consider linking to us by <a href="../link.htm">click here.</a> Enjoy your stay!</font></nobr>'this is just to give you an idea of what is possible.

Now to explain how you can make use of these modifications to have your content display as you want it to:
t1=setTimeout("copyspeed=pausespeed",3050-p);The 3050 in the above line is the number of milliseconds until the first pause.
t2=setTimeout("copyspeed=marqueespeed",6100);6100 above is how long until resume in milliseconds, a good rule of thumb is to make it double the initial timeout. To understand how long the pause will be in this case, subtract the 3050 from the 6100.

t3=setTimeout("strstp()",6200);this last timeout starts things over and should be just a tad longer than the resume value.

That is just about it. You will see a fudge value of p=40 which appears twice in the scrollmarquee function. For some reason this is needed to synchronize subsequent iterations with the initial one. The higher your speed the smaller this will have to be and it can vary if your initial pause timeout value varies, adjust this last to get things to line up in subsequent run throughs once the initial run through is to your satisfaction. Do not adjust the two p=0 statements. You can, as I hinted earlier, use the &nbsp; character to alter the spacing so things line up in a pleasing fashion. Enjoy!

jscheuer1
04-14-2005, 05:13 AM
Just in case that is too much to deal with, here is a version that looks more like a DD script, with the only configuration needed at the top of the script, before the:
////NO NEED TO EDIT BELOW THIS LINE////////////with comments to give you an idea of what to do. Plus, it is a working demo!