473,652 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Snowflake code works in IE and Opera, but not in Firefox and Safari

3 New Member
This is a java script code that will make it snow on your page. My problem is that it works just fine in IE and Opera, but doesn't work in Fire Fox or Safari. Here is the code. If you have any idea why i can't get it to work that would be great!

Expand|Select|Wrap|Line Numbers
  1. <!-- this script got from www.javascriptfreecode.com-Coded by: Krishna Eydatoula -->
  2. <!-- Web Site:  http://www.javakhafan.9f.com-->
  3. <!-- javakhafan.9f.com -->
  4. <script>
  5. // Set the number of snowflakes (more than 30 - 40 not recommended)
  6. var snowmax=35
  7.  
  8. // Set the colors for the snow. Add as many colors as you like
  9. var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD")
  10.  
  11. // Set the fonts, that create the snowflakes. Add as many fonts as you like
  12. var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS")
  13.  
  14. // Set the letter that creates your snowflake (recommended:*)
  15. var snowletter="*"
  16.  
  17. // Set the speed of sinking (recommended values range from 0.3 to 2)
  18. var sinkspeed=0.6
  19.  
  20. // Set the maximal-size of your snowflaxes
  21. var snowmaxsize=22
  22.  
  23. // Set the minimal-size of your snowflaxes
  24. var snowminsize=8
  25.  
  26. // Set the snowing-zone
  27. // Set 1 for all-over-snowing, set 2 for left-side-snowing 
  28. // Set 3 for center-snowing, set 4 for right-side-snowing
  29. var snowingzone=3
  30.  
  31. ///////////////////////////////////////////////////////////////////////////
  32. // CONFIGURATION ENDS HERE
  33. ///////////////////////////////////////////////////////////////////////////
  34.  
  35.  
  36. // Do not edit below this line
  37. var snow=new Array()
  38. var marginbottom
  39. var marginright
  40. var timer
  41. var i_snow=0
  42. var x_mv=new Array();
  43. var crds=new Array();
  44. var lftrght=new Array();
  45. var browserinfos=navigator.userAgent 
  46. var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
  47. var ns6=document.getElementById&&!document.all
  48. var opera=browserinfos.match(/Opera/)  
  49. var browserok=ie5||ns6||opera
  50.  
  51. function randommaker(range) {        
  52.     rand=Math.floor(range*Math.random())
  53.     return rand
  54. }
  55.  
  56. function initsnow() {
  57.     if (ie5 || opera) {
  58.         marginbottom = document.body.clientHeight
  59.         marginright = document.body.clientWidth
  60.     }
  61.     else if (ns6) {
  62.         marginbottom = window.innerHeight
  63.         marginright = window.innerWidth
  64.     }
  65.     var snowsizerange=snowmaxsize-snowminsize
  66.     for (i=0;i<=snowmax;i++) {
  67.         crds[i] = 0;                      
  68.         lftrght[i] = Math.random()*15;         
  69.         x_mv[i] = 0.03 + Math.random()/10;
  70.         snow[i]=document.getElementById("s"+i)
  71.         snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
  72.         snow[i].size=randommaker(snowsizerange)+snowminsize
  73.         snow[i].style.fontSize=snow[i].size
  74.         snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
  75.         snow[i].sink=sinkspeed*snow[i].size/5
  76.         if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
  77.         if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
  78.         if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
  79.         if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
  80.         snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size)
  81.         snow[i].style.left=snow[i].posx
  82.         snow[i].style.top=snow[i].posy
  83.     }
  84.     movesnow()
  85. }
  86.  
  87. function movesnow() {
  88.     for (i=0;i<=snowmax;i++) {
  89.         crds[i] += x_mv[i];
  90.         snow[i].posy+=snow[i].sink
  91.         snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
  92.         snow[i].style.top=snow[i].posy
  93.  
  94.         if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
  95.             if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
  96.             if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
  97.             if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
  98.             if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
  99.             snow[i].posy=0
  100.         }
  101.     }
  102.     var timer=setTimeout("movesnow()",50)
  103. }
  104.  
  105. for (i=0;i<=snowmax;i++) {
  106.     document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
  107. }
  108. if (browserok) {
  109.     window.onload=initsnow
  110. }
  111. </script>
Expand|Select|Wrap|Line Numbers
  1. <font face="Tahoma"><a target="_blank" href="http://www.javascriptfreecode.com/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
Dec 13 '07 #1
5 2289
JosAH
11,448 Recognized Expert MVP
You do realize that this is a Java forum and Java and Javascript are two entirely
different things? I'll move your question over to the Javascript forum.

kind regards,

Jos
Dec 13 '07 #2
mrhoo
428 Contributor
There are no properties called posx or posy in firefox or safari- and they haven't been used much in IE since IE4.
Dec 13 '07 #3
IndependentDreams
3 New Member
You do realize that this is a Java forum and Java and Javascript are two entirely
different things? I'll move your question over to the Javascript forum.

kind regards,

Jos

LoL. Sorry, I knew that but just didn't catch that. Thanks
Dec 13 '07 #4
IndependentDreams
3 New Member
I have fixed this up a lot but still have not got it to work on Firefox or Safari. It will work on IE and Opera. If you have advice on what else do do or what i might have missed that would be great!

Expand|Select|Wrap|Line Numbers
  1. // Set the number of snowflakes (more than 30 - 40 not recommended)
  2. var snowmax=40
  3.  
  4. // Set the colors for the snow. Add as many colors as you like
  5. var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD")
  6.  
  7. // Set the fonts, that create the snowflakes. Add as many fonts as you like
  8. var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS")
  9.  
  10. // Set the letter that creates your snowflake (recommended:*)
  11. var snowletter="*"
  12.  
  13. // Set the speed of sinking (recommended values range from 0.3 to 2)
  14. var sinkspeed=1.0
  15.  
  16. // Set the maximal-size of your snowflaxes
  17. var snowmaxsize=22
  18.  
  19. // Set the minimal-size of your snowflaxes
  20. var snowminsize=10
  21.  
  22. // Set the snowing-zone
  23. // Set 1 for all-over-snowing, set 2 for left-side-snowing 
  24. // Set 3 for center-snowing, set 4 for right-side-snowing
  25. var snowingzone=1
  26.  
  27. ///////////////////////////////////////////////////////////////////////////
  28. // CONFIGURATION ENDS HERE
  29. ///////////////////////////////////////////////////////////////////////////
  30.  
  31.  
  32. // Do not edit below this line
  33. var snow=new Array()
  34. var marginbottom
  35. var marginright
  36. var timer
  37. var i_snow=0
  38. var x_mv=new Array();
  39. var crds=new Array();
  40. var lftrght=new Array();
  41. var browserinfos=navigator.userAgent 
  42. var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
  43. var ns6=document.getElementById&&!document.all
  44. var opera=browserinfos.match(/Opera/) 
  45. var safari=browserinfos.match(/Apple/)
  46. var mozilla=navigator.userAgent.match(/Mozilla/) 
  47. var browserok=ie5||ns6||opera||mozilla||safari
  48. browserok=true
  49.  
  50. function randommaker(range) {        
  51.     rand=Math.floor(range*Math.random())
  52.     return rand
  53. }
  54.  
  55. function initsnow() {
  56.         marginbottom=10
  57.         marginright=10
  58.     if (ie5 || opera) {
  59.         marginbottom = document.body.clientHeight
  60.         marginright = document.body.clientWidth
  61.     }
  62.     else if (ns6) {
  63.         marginbottom = window.innerHeight
  64.         marginright = window.innerWidth
  65.     }
  66.     var snowsizerange=snowmaxsize-snowminsize
  67.     for (i=0;i<=snowmax;i++) {
  68.         crds[i] = 0;                      
  69.         lftrght[i] = Math.random()*15;         
  70.         x_mv[i] = 0.03 + Math.random()/10;
  71.         snow[i]=document.getElementById("s"+i)
  72.         snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
  73.         snow[i].size=randommaker(snowsizerange)+snowminsize
  74.         snow[i].style.fontSize=snow[i].size
  75.         snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
  76.         snow[i].sink=sinkspeed*snow[i].size/5
  77.         if (snowingzone==1) {snow[i].x=randommaker(marginright-snow[i].size)}
  78.         if (snowingzone==2) {snow[i].x=randommaker(marginright/2-snow[i].size)}
  79.         if (snowingzone==3) {snow[i].x=randommaker(marginright/2-snow[i].size)+marginright/4}
  80.         if (snowingzone==4) {snow[i].x=randommaker(marginright/2-snow[i].size)+marginright/2}
  81.         snow[i].y=randommaker(2*marginbottom-marginbottom-2*snow[i].size)
  82.         snow[i].style.left=snow[i].x
  83.         snow[i].style.top=snow[i].y
  84.     }
  85.     movesnow()
  86. }
  87.  
  88. function movesnow() {
  89.     for (i=0;i<=snowmax;i++) {
  90.         crds[i] += x_mv[i];
  91.         snow[i].y+=snow[i].sink
  92.         snow[i].style.left=snow[i].x+lftrght[i]*Math.sin(crds[i]);
  93.         snow[i].style.top=snow[i].y
  94.  
  95.         if (snow[i].y>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
  96.             if (snowingzone==1) {snow[i].x=randommaker(marginright-snow[i].size)}
  97.             if (snowingzone==2) {snow[i].x=randommaker(marginright/2-snow[i].size)}
  98.             if (snowingzone==3) {snow[i].x=randommaker(marginright/2-snow[i].size)+marginright/4}
  99.             if (snowingzone==4) {snow[i].x=randommaker(marginright/2-snow[i].size)+marginright/2}
  100.             snow[i].y=0
  101.         }
  102.     }
  103.     var timer=setTimeout("movesnow()",50)
  104. }
  105.  
  106. for (i=0;i<=snowmax;i++) {
  107.     document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
  108. }
  109. if (browserok) {
  110.     window.onload=initsnow
  111. }
Dec 13 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
I've merged the threads and changed the thread title. Makes everything a lot cleaner and easier.
Dec 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
8886
by: Sander Tekelenburg | last post by:
While working on <http://www.lotzofmusic.com/> I ran into some issues with overflow (the decorative fishes). It seems to me the construction is sound, yet Safari ignores the overflow:hidden. At first glance it appeared that this is related to the fact that the SPANs contain only a background image and have a defined width & height, but no: I put up a simplified test-case at <http://santek.no-ip.org/~st/tests/CSS/overflow_hidden.php>,...
3
2020
by: mr_burns | last post by:
hi, i am using the following code which works well in internet explorer but not in firefox (and perhaps others too): var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("xml/names.xml"); nodes = xmlDoc.documentElement.childNodes span_html = '<p>'
3
13054
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there doesn't appear to be any standardised keyboard event interface other than this DOM 3 Events W3C Working Group Note . However, it is only a note and doesn't appear to be implemented in any browser. Is there another standard that I've missed? The...
5
3339
by: warteschlange | last post by:
i want to postload javscript from another javascript. This works fine in firefox and IE6 for macIE i can use an Iframe to load the code and inject it with insertAdjacentHTML The problems arise with safari and opera. both load the new code with XMLHttpRequest, but the code is no 'executable' To make this possible on IE i had to use the magic 'DEFER' attribute.
2
1317
by: Mark Rae | last post by:
Hi, I've just finished upgrading a site for a client to XHTML-compliance. It's been tested on the latest versions of the following OS / browser combinations: WinXP - IE WinXP - Netscape WinXP - FireFox WinXP -Opera
16
47679
by: Steve Chapel | last post by:
When I load the page <https://bugzilla.mozilla.org/attachment.cgi?id=237739with Internet Explorer 7 RC 1, I get the error "Object Expected" at line 174. When I click on the button, I also get the same error on line 186. This same HTML and JavaScript works perfectly in Firefox and Opera. How can I make the code work in IE?
8
1766
by: Candoer | last post by:
I am new to both HTML and CSS. Several months ago my High School Alumni association web master died and they asked me to take over the web site. I had never worked with CSS but had some experience with HTML. The site was written strictly using HTML and had no CSS. So I decided to take on the task to convert it using CSS. For the past three months I have been lurking on this group and trying my best to absorb your suggestions to others and...
4
1816
by: AG | last post by:
Using ASP.NET 3.5 I have been using a standard menu control bound to a sitemapdatasource using a web.sitemap file. The menus work fine in IE and Firefox, but in Safari, they render horribly and dynamic menus don't work at all. I found a post indicating that rendering can be improved by modifying browserCaps, but not the dynamic functionality. A search finds many third party menu controls. Most of which utilize their own xml file source.
4
1550
by: maureen1708 | last post by:
Hi, A noob here so please be gentle :) I am revamping my dog's website (don't laugh, he's what got me off the couch to learn a little html/css in the first place). Everything seems to work fine in IE7, Opera, and Safari, but in Firefox, the second page is wonky until I hit refresh (I've only got the two pages so far). Here's the site: http://brt.50webs.org/index.html On the second page, the image and text in colOne that should be...
2
4769
by: rudiedirkx | last post by:
Gents, I have a problem (only in Safari) with the onsubmit in webforms. This topic covers the same subject: http://bytes.com/topic/javascript/answers/166542-onsubmit-safari but not as detailed as I will. Let me illustrate the problem with examples. The HTML: <html> <head> <script type="text/javascript" src="/js/mootools_1_11.js"></script>
0
8370
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.