emery Posted January 25, 2012 Share Posted January 25, 2012 I have this code It doesn't work in IE but works in chrome/FF <script src="snow.js" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ window.onload = function() { try { snow.count = 30; // number of flakes snow.delay = 20; // timer interval snow.minSpeed = 2; // minimum movement/time slice snow.maxSpeed = 5; // maximum movement/time slice snow.start(); } catch(e) { // no snow } }; //]]> </script> Quote Link to comment https://forums.phpfreaks.com/topic/255720-javascript-help-in-php/ Share on other sites More sharing options...
joel24 Posted January 25, 2012 Share Posted January 25, 2012 what part of it is not working? try run <script src="snow.js" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ window.onload = function() { alert("working..."); try { snow.count = 30; // number of flakes snow.delay = 20; // timer interval snow.minSpeed = 2; // minimum movement/time slice snow.maxSpeed = 5; // maximum movement/time slice snow.start(); } catch(e) { // no snow } }; //]]> </script> if it isn't working, attach it to your <body onload="function"> event. otherwise - what is snow.js? Quote Link to comment https://forums.phpfreaks.com/topic/255720-javascript-help-in-php/#findComment-1310905 Share on other sites More sharing options...
emery Posted January 25, 2012 Author Share Posted January 25, 2012 What ??? What do I attach it to? And I will post the .js file when I can (10hrs) approx Quote Link to comment https://forums.phpfreaks.com/topic/255720-javascript-help-in-php/#findComment-1310939 Share on other sites More sharing options...
emery Posted January 26, 2012 Author Share Posted January 26, 2012 The site is at http://snowblazers.tk snow = { count: 60, delay: 10, flutter: 0.2, wind: 1.0, w1: 1, minSpeed: 0.3, maxSpeed: 4, cv: null, flakes: [], toggle: function() { if(window.snowtimer) snow.stop(); else snow.start(); }, resize: function() { snow.cv.width = innerWidth; snow.cv.height = innerHeight; snow.gt = snow.ct.createLinearGradient(0,0,0,snow.cv.height); snow.gt.addColorStop(0.0, '#6666ff'); snow.gt.addColorStop(1.0, '#ffffff'); snow.ct.fillStyle = snow.gt; }, start: function() { snow.cv = document.createElement('canvas'); snow.cv.width = snow.cv.height = 10; // set initial size snow.cv.id = 'backgroundSnowCanvas'; document.body.appendChild(snow.cv); snow.createFlake(); snow.ct = snow.cv.getContext('2d'), snow.cv.style.position = 'absolute'; snow.cv.style.top = 0; snow.cv.style.left = 0; snow.cv.style.zIndex = -1; snow.resize(); var c = snow.count; snow.flakes = []; do { snow.flakes.push(new snow.flake()); } while(--c); snow.ct.fillRect(0,0,snow.cv.width,snow.cv.height); window.snowtimer = window.setInterval(snow.draw, snow.delay); window.addEventListener('resize',snow.resize); }, stop: function() { window.clearInterval(window.snowtimer); var c = document.getElementById('backgroundSnowCanvas'); c.parentNode.removeChild(c); window.snowtimer=snow=null; }, draw: function() { var ct = snow.ct, f = snow.flakes, c = snow.count; ct.fillRect(0,0,snow.cv.width,snow.cv.height); do { if(f[--c].draw(ct) && ++fdone) { }; } while(c); snow.wind += Math.cos(snow.w1++ / 180.0); }, flake: function() { this.draw = function(ct) { ct.drawImage(snow.flakeImage,this.x + snow.wind,this.y,this.sz,this.sz); this.animate(); }; this.animate = function() { this.y += this.speed; this.x += this.flutter * Math.cos(snow.flutter * snow.flutter * this.y); if(this.y > innerHeight) this.init(1); }; this.init = function(f) { this.speed = snow.minSpeed + (Math.random() * (snow.maxSpeed - snow.minSpeed)); this.sz = ~~(Math.random() * 40) + 20; this.flutter = ~~(Math.random() * snow.flutter * (60-this.sz)); this.x = (Math.random() * (innerWidth + this.sz)) - this.sz; this.y = f ? -this.sz : Math.random() * innerHeight; }; this.init(); }, createFlake: function() { snow.flakeImage = document.createElement('canvas'); snow.flakeImage.width = snow.flakeImage.height = 40; var c = snow.flakeImage.getContext('2d'); c.fillStyle = '#fff'; c.translate(20,20); c.beginPath(); c.rect(-5,-20,10,40); c.rotate(Math.PI / 3.0); c.rect(-5,-20,10,40); c.rotate(Math.PI / 3.0); c.rect(-5,-20,10,40); c.closePath(); c.fill(); }, }; Quote Link to comment https://forums.phpfreaks.com/topic/255720-javascript-help-in-php/#findComment-1311311 Share on other sites More sharing options...
nogray Posted January 26, 2012 Share Posted January 26, 2012 In your snow.js, remove the comma behind the last item in the object c.fill(); }// remove this comma , }; Quote Link to comment https://forums.phpfreaks.com/topic/255720-javascript-help-in-php/#findComment-1311327 Share on other sites More sharing options...
emery Posted January 26, 2012 Author Share Posted January 26, 2012 Thanks, i have done this but my hosting has gone down for about 24hours :'( Quote Link to comment https://forums.phpfreaks.com/topic/255720-javascript-help-in-php/#findComment-1311463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.