PDA

View Full Version : Modification of "Cross browser Marquee script" to dynamic width



anycall
09-07-2008, 10:36 AM
I was made simple changes to "Cross browser Marquee script", but please, tell me, that's a good solution? And one trouble - if i resize a window after loading script does not recalculating results, please if you can, help me use OnResize event, i don't know JavaScript:(

function getClientWidth()
{
return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
var MyWidth = getClientWidth()



//Specify the marquee's width (in pixels)
var marqueewidth= MyWidth

jscheuer1
09-07-2008, 01:35 PM
Warning: Please include a link to the DD script in question in your post. See this thread (http://www.dynamicdrive.com/forums/showthread.php?t=6) for the proper posting format when asking a question.

Please post a link to the page on your site that contains the problematic code so we can check it out.

anycall
09-22-2008, 08:34 AM
One kind men write script with my needs, but have two not solved troubles...
First - i want to see text in loop without vaiting for going out text before seeng repeat, i want to see "powerfull marquee script | This is the most " and the second - if i have long string i see horizontal scroller in browser:( But script are working:

<script>
// настройка скорости
delay = 30;
step = 2;

is_start = true;
fullwidth = 0;
cpos = 0;
scrollw = 0;

function start_scroll()
{
var scrolltext = document.getElementById('scrolltext');
var scroll = document.getElementById('scroll');

fullwidth = scrolltext.offsetWidth;
scrolltext.style.left = scroll.offsetWidth;
scrollw = scroll.offsetWidth;
scrolltext.style.position = 'relative';

myinterval = setInterval(do_scroll, delay);
}

function do_scroll()
{
var scroll = document.getElementById('scroll');
var scrolltext = document.getElementById('scrolltext');

if (is_start)
{
cpos = scroll.offsetWidth;
scrolltext.style.left = cpos;
is_start = false;
}
else
{
cpos -= step;
scrolltext.style.left = cpos;
if (cpos < -fullwidth) { is_start = true; }
}
}

function stop_scroll()
{
clearInterval(myinterval);
}

function continue_scroll()
{
myinterval = setInterval(do_scroll, delay);
}

function do_resize()
{
var scroll = document.getElementById('scroll');
newscrollw = scroll.offsetWidth;

if (cpos >= 0) { absstp = scrollw - cpos; }
else { absstp = scrollw + Math.abs(cpos); }

oldprc = absstp / (scrollw + fullwidth);
newlen = newscrollw + fullwidth;
newabsstp = newlen * oldprc;

if (newabsstp <= newscrollw) { cpos = newscrollw - newabsstp; }
else { cpos = -(newabsstp - newscrollw); }

scrollw = newscrollw;
}
</script>

<style>
#scroll {width: 100%;
background-color: f0f0f0;
white-space: nowrap;
overflow: hidden;
position: relative}
#scrolltext {position: absolute}
</style>

<body onload='start_scroll()' onresize='do_resize()'>

<div style='width:100%'>

<div id='scroll' onmouseover='stop_scroll()'
onmouseout='continue_scroll()'>
<div id='scrolltext'>
Здесь скроллируемый текст,
его скорость настраивается,
в нем есть <a href=''>ссылка</a>,
при наведении мыши он останавливается
</div>
</div>

</div>

</body>