/    Sign up×
Community /Pin to ProfileBookmark

Javascript Scroller Slow Performance

Hello,

I wrote a small script to scroll some images within a div based view/canvas page. The following is the script:

[CODE]var currentPosition = 0;
var canvasHeight = 445; //dynamically set
var viewHeight = 273; //never changes
var timeoutId;

function homeBodySchoolThumbsScrollUp() {
currentPosition = getSchoolThumbsCanvasTopPosition();
if (currentPosition > (-(canvasHeight – viewHeight) – 10)) {
currentPosition–;
setSchoolThumbsCanvasTopPosition(currentPosition);
timeoutId = setTimeout(‘homeBodySchoolThumbsScrollUp()’, 1);
}
}

function homeBodySchoolThumbsScrollDown() {
currentPosition = getSchoolThumbsCanvasTopPosition();
if (currentPosition < 0) {
currentPosition++;
setSchoolThumbsCanvasTopPosition(currentPosition);
timeoutId = setTimeout(‘homeBodySchoolThumbsScrollDown()’, 1);
}
}

function clearScrollTimeout() {
clearTimeout(timeoutId);
}

function getSchoolThumbsCanvasTopPosition() {
var top = document.getElementById(‘home-body-school-thumbs-canvas’).style.top;
return new Number(top.slice(0, top.length – 2));
}

function setSchoolThumbsCanvasTopPosition(num) {
document.getElementById(‘home-body-school-thumbs-canvas’).style.top = num + “px”;
}[/CODE]

In Chrome this worked at an acceptable speed. However, in Firefox and Internet Explorer is really slow. Since the majority of my tests have been slow I’m thinking the script itself is the issue and I’m not doing something correctly.

The ScrollUp and ScrollDown functions are call onmouseover in the respective divs.

Any tips? Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mhoaglandauthorAug 13.2010 — *bamp*
×

Success!

Help @mhoagland 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 5.7,
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,
)...