I have a Javascript function for Marquee animation in my ASP.NET Masterpage that runs fine when the page is first loaded, but then stops when a page button is pressed. Any idea how to fix this?
I got help from here, Javascript Marquee to replace <marquee> tags
Using the second answer
window.addEventListener('load', function () {
function go() {
i = i < width ? i + step : 1;
m.style.marginLeft = -i + 'px';
}
var i = 0,
step = 3,
space = ' ';
var m = document.getElementById('marquee');
var t = m.innerHTML; //text
m.innerHTML = t + space;
m.style.position = 'absolute'; // http://stackoverflow.com/questions/2057682/determine-pixel-length-of-string-in-javascript-jquery/2057789#2057789
var width = (m.clientWidth + 1);
m.style.position = '';
m.innerHTML = t + space + t + space + t + space + t + space + t + space + t + space + t + space;
m.addEventListener('mouseenter', function () {
step = 0;
}, true);
m.addEventListener('mouseleave', function () {
step = 3;
}, true);
var x = setInterval(go, 50);
}, true);
HTML
<div id="marquee">
1 Hello world! 2 Hello world! <a href="#">3 Hello world!</a>
</div>
CSS
#marquee {
background:#eee;
overflow:hidden;
white-space: nowrap;
}