Hi friends, please, how to adapt a delay on 6 seconds before start the div scroller again ?
I need, end the scroll, go back to the start, and pause for 6 seconds before starting again ( automatic ) the scroller.
Thanks !
This script:
Auto-scrolling a DIV-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Auto Scroller</title>
<style type='text/css'>
#MyDivName {
overflow:auto;
width:200px;
height:100px;
}
</style>
<script language="javascript">
window.onload = function() {
scrollDiv_init();
};
ScrollRate = 10;
function scrollDiv_init() {
DivElmnt = document.getElementById('MyDivName');
DivElmnt.onmouseover = pauseDiv;
DivElmnt.onmouseout = resumeDiv;
ReachedMaxScroll = false;
DivElmnt.scrollTop = 0;
PreviousScrollTop = 0;
ScrollInterval = setInterval('scrollDiv()', ScrollRate);
}
function scrollDiv() {
if (!ReachedMaxScroll) {
DivElmnt.scrollTop = PreviousScrollTop;
PreviousScrollTop++;
ReachedMaxScroll = DivElmnt.scrollTop >= (DivElmnt.scrollHeight - DivElmnt.offsetHeight);
}
else {
DivElmnt.scrollTop = PreviousScrollTop = 0;
ReachedMaxScroll = false;
/*
ReachedMaxScroll = (DivElmnt.scrollTop == 0)?false:true;
DivElmnt.scrollTop = PreviousScrollTop;
PreviousScrollTop--;
*/
}
}
function pauseDiv() {
clearInterval(ScrollInterval);
}
function resumeDiv() {
PreviousScrollTop = DivElmnt.scrollTop;
ScrollInterval = setInterval('scrollDiv()', ScrollRate);
}
</script>
</head>
<body>
<div id="MyDivName">
11111 11111 11111<br>22222 22222 22222<br>text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text<br>Almost Last Row<br>text text text<br>Last Row
</div>
</body>
</html>
Please, It is possible to call a php variable in the code, I need to control the scroll speed and the delay by php, I made this change but it did not work:
For the PHP to work, the file needs to be “,php” and not “.html” (well, unless you have things configured for it) I’m assuming you know this but just in case.
Anyway, my guess is that “short tags” aren’t enabled. Try
Yes, PHP page, I know. But it does not work.
I have other variables that I capture via GET in other scripts. All other working. But in this case it is as if there is nothing in the ScrollRate item, it only recognizes a direct number. Weird.
Just as a side note, you should never evaluate code like this without need – it’s both dangerous and slow. Instead, you can simply pass the function itself to the timeout like
setTimeout(resumeDiv, 1000);
You might have a look at the MDN page on eval() for details why such string representations should be avoided.