|
|
Subject:
Tweak javascript to make it work in Netscape 4.7
Category: Computers > Internet Asked by: gan-ga List Price: $5.00 |
Posted:
18 Feb 2003 16:33 PST
Expires: 20 Mar 2003 16:33 PST Question ID: 163202 |
Tweak javascript to make it work in Netscape 4.7 : (initially stationary image to slide across horizontally, stop, then slide along a bit more.) works in ie6 (or did before anyway ;-) this might not be possible in Netscape 4.7? 01 <html> 02 <head> 03 04 <script type="text/javascript"> 05 <!-- 06 var currentPosition=30; 07 08 function slideImageIntoView() 09 10 { 11 currentPosition++; 12 myimage.style.left = currentPosition; if(currentPosition > 127) { setTimeout("slideImageOutOfView()",5000); } else { setTimeout("welcomeMsg()",1); } } function slideImageOutOfView() { currentPosition++; myimage.style.left = currentPosition; if(currentPosition > 219) { exit(1); } else { setTimeout("slideImageOutOfView()",1); } } //--> </script> <style type="text/css"> <!-- #myimage{position:absolute;top:12px;left:30px} --> </style> </head> <body onLoad="slideImageIntoView()"> <img id="myimage" src="someimage.gif" alt=""> <!-- error message in netscape 4.7: JavaScript Error: http://mydomain/thisfile.html, line 12: myimage is not defined. --> </body> </html> | |
| |
| |
|
|
Subject:
Re: Tweak javascript to make it work in Netscape 4.7
Answered By: j_philipp-ga on 18 Feb 2003 20:53 PST Rated: |
Hello Gan, Try the follwing: ----- <html> <head> <title>Sample</title> <script type="text/javascript"> <!-- var currentPosition = 30; function slideImageIntoView() { currentPosition += 5; positionLayer("layer1", 30, currentPosition); if (currentPosition < 127) { setTimeout("slideImageIntoView()", 60); } else { setTimeout("welcomeMsg()", 1); } } function slideImageOutOfView() { currentPosition -= 5; positionLayer("layer1", 30, currentPosition); if (currentPosition > -100) { setTimeout("slideImageOutOfView()", 60); } } function positionLayer(lrName, x, y) { if (document.all) { document.all[lrName].style.left = x + "px"; document.all[lrName].style.top = y + "px"; } else if (document.layers) { document.layers[lrName].left = x; document.layers[lrName].top = y; } else if (document.getElementById) { elem = document.getElementById(lrName); elem.style.left = x + "px"; elem.style.top = y + "px"; } } function welcomeMsg() { alert("Welcome"); slideImageOutOfView(); } //--> </script> </head> <body onLoad="slideImageIntoView()"> <div style="position: absolute; top: 12px; left: 30px" id="layer1"> <img src="at.gif" alt=""> </div> </body> </html> ----- The image will move down, display the "Welcome" message, then move up again and out of the browser area. While you might want to change the behavior, the important function here is "positionLayer". It's a general function to position a layer and you may want to reuse it for other JavaScripts as well. It tests the browser's object model to then go into separate lines for each. Above HTML has been tested with Netscape Navigator 4.7 [1]. In general, "document.layer" is used for Netscape 4x, "document.all" for Internet Explorer and the standard "document.getElementById" for newer versions of Internet Explorer, as well as the more recent Netscape versions. I hope it helps! Footnotes: [1] Netscape 4.7 can be found at: Browser Archive http://browsers.evolt.org/ Search strategy: (none) |
gan-ga
rated this answer:
and gave an additional tip of:
$5.00
j_philipp, your code does just what I want - thank you very much; I'd become rather frustrated with this! |
|
Subject:
Re: Tweak javascript to make it work in Netscape 4.7
From: j_philipp-ga on 19 Feb 2003 01:08 PST |
Gan, thanks for the nice rating & tip -- good luck with future coding! |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |