/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] onLoad code interferes with auto scroll code

Hi,
I have this code:

[CODE]onLoad=”MM_preloadImages(‘img/nav_contactR.jpg’, ‘img/nav_bioR.jpg’,’img/nav_artR.jpg’,’img/nav_referencesR.jpg’)”[/CODE]

on this page:
[URL=http://www.xn3ct.net/SampleSite04/index.html]http://www.xn3ct.net/SampleSite04/index.html[/URL] right at the beginning of the [B]<body>[/B] that interferes with the code I have for having automatic scrolling for the content of the DIV (in that case I only have text in the div).
The scroll doesn’t work right now, but when I remove the [B]onLoad[/B] code, the scroll works OK. How can I still keep the [B]onLoad[/B] code, yet have the scroll working?
The link to the JS for the scroll:
[URL=http://www.xn3ct.net/SampleSite04/js/scrollDiv.js]http://www.xn3ct.net/SampleSite04/js/scrollDiv.js[/URL] Thanks.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KramyMar 30.2006 — You could try adding the initScroll into the body onLoad, and removing it from the script.

[CODE]onLoad="MM_preloadImages('img/nav_contactR.jpg','img/nav_bioR.jpg','img/nav_artR.jpg','img/nav_referencesR.jpg'); initScroll();"[/CODE]
Copy linkTweet thisAlerts:
@jamesx521authorMar 31.2006 — But, are you saying that I should post [B]the whole[/B] scroll code into the [B]<body> [/B] and then get rid off of the JS scroll external source code? That's a lot of code to be put in the [B]<body>[/B]! Can I instead remove the line of JS code from the [B]<body>[/B] and put it into any one of the two external JS files I have?
Copy linkTweet thisAlerts:
@KramyMar 31.2006 — No, I mean the body has an onLoad="DoThisStuff();", but the script has an onLoad=CallThisFunction;

Try removing the onLoad from inside the script file and adding the call to it onto the end of the body onLoad. My logic says if an onLoad isn't firing, try cutting the number of them from 2 to 1.
Copy linkTweet thisAlerts:
@jamesx521authorApr 01.2006 — Yes, that did work -- Thanks -- you can see the result on:

http://www.xn3ct.net/SampleSite04/art.html

However, there is still a problem (with the scroll code itself probably). I am getting mixed results:

Click on the scroll bar of the automatic scroll and move it. You'll see that once you let it go, it will not continue auto scrolling from where you let it go, but from where you had picked the scroll bar initially. Or, once you move the scroll bar, the auto scroll doesn't continue anymore until you refresh the page and it starts from the beginning.
Copy linkTweet thisAlerts:
@KramyApr 01.2006 — You have duplicate scroll code - main.js and scrollDiv.js both have overlapping function names. Delete the scroll code from one or the other.

Also, less code is more, so maybe this will work better? ?
[CODE]<!--
var ScrolledDiv = 0;
var ScrollPaused = false;
var ScrollTimer = 0;

function doScroll()
{
if(!ScrollPaused)
{
var ResetCheck = ScrolledDiv.scrollTop;

ScrolledDiv.scrollTop += 3; // Speed/Pixel-Jump Adjuster

if(ScrolledDiv.scrollTop == ResetCheck) ScrollTimer = setTimeout('ScrolledDiv.scrollTop = 0; doScroll();', 6000); // Reset Timer
else ScrollTimer = setTimeout('doScroll();', 100) // Speed/Smoothness Adjuster
}
else setTimeout("doScroll();", 1000);
}

function initScroll(){
ScrolledDiv = document.getElementById('autoscroll');
ScrolledDiv.scrollTop = 0;
setTimeout("doScroll();",1000);

ScrolledDiv.onMouseOver = function() { ScrollPaused = true; clearTimeout(ScrollTimer); }
ScrolledDiv.onMouseOut = function() { ScrollPaused = false; doScroll(); }
}
//-->[/CODE]
×

Success!

Help @jamesx521 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...