Skip to main content
Home Forums Silverlight Programming Programming with JavaScript bug with increasing the size of image
3 replies. Latest Post by brightstar on October 19, 2009.
(0)
brightstar
Member
406 points
185 Posts
10-18-2009 7:36 PM |
Hello every body!
I have the two next listings:
This example DOESN'T WORK!
1 <script> 2 3 function oleg() 4 { 5 var a = document; 6 7 var b = a.pic1.width; 8 9 if( b == 200 ) 10 { 11 a.pic1.width = b + 20; 12 setTimeout("oleg();", 5); 13 14 if(b == 500) 15 { 16 a.pic1.width = b; 17 } 18 } 19 } 20 21 </script> 22 23 <img src ="./1.jpg" width ="200" name ="pic1" onMouseOver ="oleg();">
And, if I shall change in line:9 from "if( b == 200 )" to "if( b > 0 )"the effect will work!I want to know, why it doesn't work?
I set at <img> the value of width: 200px.
And in the script logic, I check if ( b == 200) and you can see that the variable `b` equals 200 at <img> indeed.
Why the version with b = 200 doesn't work and if I change it to b < 0 , the effect will work?
Can somebody help me?
Best Regards,
Oleg
mokarom
123 points
23 Posts
10-18-2009 10:43 PM |
I'm not sure why its not working with you. I copied your code and its working fine with me.
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script> function oleg() { var a = document; var b = a.pic1.width; if (b == 200) { a.pic1.width = b + 20; setTimeout("oleg();", 5); if (b == 500) { a.pic1.width = b; } } } </script> </head> <body> <img src="score.bmp" width="200px" name="pic1" onmouseover="oleg();" /> </body> </html>
If I put if(b == 200), it increases the img width once to 220 and in the next run it stops increasing the width as it finds b=220. If you wanna let the image width grow as long as the mouse is over the image and until it is 500, try putting if(b>=200) instead.
Hope this helps.
sl.ayer
Participant
856 points
166 Posts
10-19-2009 12:53 AM |
How is this Silverlight related?
10-19-2009 1:42 AM |
I'm training to support Moonlight , the part of Silverlight, but on GNU\Linux.Becuase Moonlight works fine only with 1st version of Silverlight, which was XAML + JavaScript.