/    Sign up×
Community /Pin to ProfileBookmark

Opera and onclick…

Hi guys, wondering if someone can help me.

There is an image contained in a div (overflow hidden). When the user mouses over a certain link, the image inside the div is supposed to move to a different position. This works perfectly in all browsers, but when I change onmouseover to onclick, opera fails to move the image to its new location. Instead, in opera, the image shakes and then moves back to the original position of 0px no matter which link I click on.

[CODE]
function setPosition() {
var box = document.getElementById(“color_img”);
box.style.top = “0px”;
box.style.right = “0px”;
var colorList = document.getElementById(“color_list”);
var link = colorList.getElementsByTagName(“a”);
link[0].onmouseover = function() {
movePosition(“color_img”, 0, 10);
}
link[1].onmouseover = function() {
movePosition(“color_img”, 100, 10);
}
link[2].onmouseover = function() {
movePosition(“color_img”, 200, 10);
}
link[3].onmouseover = function() {
movePosition(“color_img”, 300, 10);
}
}[/CODE]

Here’s the movePosition function if it helps…

[CODE]function movePosition(element, final_x, interval) {
var box = document.getElementById(element);
if (box.movement) {
clearTimeout(box.movement);
}
var xpos = parseInt(box.style.right);
if (xpos == final_x) {
return true;
}
if(xpos < final_x) {
var dist = Math.ceil((final_x – xpos) / 10);
xpos = xpos + dist;

}
if(xpos > final_x) {
var dist = Math.floor((final_x – xpos) / 10);
xpos = xpos + dist;
}
box.style.right = xpos + “px”;
var repeat = “movePosition(‘”+element+”‘, “+final_x+”, “+interval+”)”;
box.movement = setTimeout(repeat, interval);
}[/CODE]

Am I doing something wrong? ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@snakeyeauthorJul 26.2007 — AHA! When the link was clicked, after executing the function, opera opened the link href="#", which restores the page to its original state... perhaps refreshing it. Adding [I][B][COLOR="Blue"]return false[/COLOR][/B][/I] after the function being called by onclick canceled the link and solved the problem.
×

Success!

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