/    Sign up×
Community /Pin to ProfileBookmark

JS Zoom function freaks out!

Hey there,

I’m new on these forums so if I missed a relevant post concerning this matter… sorry ?

I’m trying to write a zoom/resize function for use as navigation. This works fine but when I move the mouse over it quickly several times the image goes all freaky on me.

JS:

[CODE]function zoomIn(target) {
var which = document.getElementById(target);
var currentWidth = which.style.width.split(‘px’)[0];
var currentHeight = which.style.height.split(‘px’)[0];
var targetWidth = 84;
var targetHeight = 91;
function doZoom() {
currentWidth++;
currentHeight++;
which.style.width = currentWidth;
which.style.height = currentHeight;
if(currentWidth == targetWidth) {
clearInterval(interval);
}
}
interval = window.setInterval(doZoom, 10);
}
function zoomOut(target) {
var which = document.getElementById(target);
var currentWidth = which.style.width.split(‘px’)[0];
var currentHeight = which.style.height.split(‘px’)[0];
var targetWidth = 74;
var targetHeight = 81;
function doZoom() {
currentWidth–;
currentHeight–;
which.style.width = currentWidth;
which.style.height = currentHeight;
if(currentWidth == targetWidth) {
clearInterval(interval);
}
}
interval = window.setInterval(doZoom, 10);
}[/CODE]

(relevant) HTML:

[CODE]<img id=”eerste” onMouseOver=”zoomIn(‘eerste’)” onMouseOut=”zoomOut(‘eerste’)” src=”images/button.png” style=”width: 74px; height: 81px;”>[/CODE]

Any suggestions would be nice…

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangDec 11.2007 — Problem is with [I]interval[/I], which is in use and with what values.

Assuming standards mode, this works in IE and Fx:var interval=null;
function zoomIn(target) {
clearInterval(interval);
var which = document.getElementById(target);
var currentWidth = parseInt(which.style.width);
var currentHeight = parseInt(which.style.height);
var targetWidth = 84;
var targetHeight = 91;
function doZoom() {
currentWidth++;
currentHeight++;
which.style.width = currentWidth+'px';
which.style.height = currentHeight+'px';
if(currentWidth == targetWidth) {
clearInterval(interval);
}
}
interval = window.setInterval(doZoom, 10);
}
function zoomOut(target) {
clearInterval(interval);
var which = document.getElementById(target);
var currentWidth = parseInt(which.style.width);
var currentHeight = parseInt(which.style.height);
var targetWidth = 74;
var targetHeight = 81;
function doZoom() {
currentWidth--;
currentHeight--;
which.style.width = currentWidth+'px';
which.style.height = currentHeight+'px';
if(currentWidth == targetWidth) {
clearInterval(interval);
}
}
interval = window.setInterval(doZoom, 10);
}
Copy linkTweet thisAlerts:
@theCoenauthorDec 11.2007 — Yup, that worked. Forgot clearing the interval variable.. Thanks!!!
×

Success!

Help @theCoen 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.18,
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,
)...