Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2009, 01:25 PM   PM User | #1
Blue_Crystal
New to the CF scene

 
Join Date: Jan 2009
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Blue_Crystal is an unknown quantity at this point
Animation works on IE but not on Firefox

I made a scale animation that works on IE 7 but it does not work on Firefox 3.

The button toggles between scaling up and down.

In Firefox , it shows a weird behavior: it starts the loop for scaling up but it is quickly interrupted and return to its original scale.

What should I change in the below code to make it also functional on Firefox 3 ?

<head>

<script language="javascript">


var obj = null;

var toggle = 0;

var w = 55;

var h = 40;

var w_speed = 22;

var h_speed = 16;

function init()
{

obj = document.getElementById("vase").style;

obj.width = 55 + "px";
obj.height = 40 + "px";

}


function ChangeScale()
{


if(toggle == 0)
{
w += w_speed;
h += h_speed;

obj.width = w + "px";
obj.height = h + "px";

if(w < 550) setTimeout("ChangeScale()",1);
else
{

obj.width = 550 + "px";
obj.height = 400 + "px";

toggle = 1;

return;


}
}

else
if(toggle == 1)
{
w -= w_speed;
h -= h_speed;

obj.width = w + "px";
obj.height = h + "px";

if(w > 55) setTimeout("ChangeScale()",1);
else
{

obj.width = 55 + "px";
obj.height = 40 + "px";

toggle = 0;

return;


}
}


}


window.onload = init;



</script>



</head>

<body bgcolor="#ffffff" background="pattern_flowers.jpg" >


<div style="position:absolute; top:240px; left:90px;">
<a href="" onClick="ChangeScale()"><img id="button" src="Button.jpg"></img></a>
</div>


<div style="position:absolute; top:20px; left:400px;">
<img id="vase" src="Vase.jpg"></img>
</div>



</body>
</html>

Last edited by Blue_Crystal; 01-21-2009 at 02:12 PM.. Reason: error in the title
Blue_Crystal is offline   Reply With Quote
Old 01-21-2009, 03:12 PM   PM User | #2
smeagol
Regular Coder

 
Join Date: Jul 2002
Location: Kentucky
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
smeagol is an unknown quantity at this point
This seems to work for me.
__________________
Kevin
Kevin Adams | Compiled Code
smeagol is offline   Reply With Quote
Old 01-21-2009, 05:30 PM   PM User | #3
Blue_Crystal
New to the CF scene

 
Join Date: Jan 2009
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Blue_Crystal is an unknown quantity at this point
Quote:
Originally Posted by smeagol View Post
This seems to work for me.
Hi smeagol

Did you test it in firefox 3 ?
Blue_Crystal is offline   Reply With Quote
Old 01-22-2009, 12:36 AM   PM User | #4
auslin
New Coder

 
Join Date: Jun 2008
Posts: 80
Thanks: 2
Thanked 16 Times in 16 Posts
auslin is an unknown quantity at this point
I find that if the link' s href attribute is removed or nullified, the animation will then continue OK in Firefox instead of stopping prematurely (it works regardless in IE):

Code:
<a href="#" onClick="ChangeScale()">
    <img id="button" src="Button.jpg"></img>
</a>
auslin is offline   Reply With Quote
Users who have thanked auslin for this post:
Blue_Crystal (01-22-2009)
Old 01-22-2009, 05:21 AM   PM User | #5
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
See if adding highlighted helps:
Code:
onClick="ChangeScale();return false;">
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Users who have thanked rangana for this post:
Blue_Crystal (01-22-2009)
Old 01-22-2009, 04:45 PM   PM User | #6
Blue_Crystal
New to the CF scene

 
Join Date: Jan 2009
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Blue_Crystal is an unknown quantity at this point
Thank you very much to you both, auslin and rangana.

Boths solutions WORK !

The funny thing is that I knew in the past ( I did not program with javascript since 8 years ago ) that somehow I need to use the symbol "#" in the href parameter when there was not real url address to assign to. But I did not know that it messes up with the javascript code ( when it runs in firefox ) if the symbol is not used.
But since empty quotes alone worked in IE, I wrongly assumed that it was not important.

Bad assumption...
Blue_Crystal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:43 PM.


Advertisement
Log in to turn off these ads.