Перейти к контенту

Скрипт снега


Рекомендуемые сообщения

Есть скрипт снега, работающий во всех браузерах на всех версиях форумов инвижена и воблы. но он грузет процессор личного компа: брался осюда - www.schillmania.com

 

/*
  DHTML PNG Snowstorm! OO-style Jascript-based Snow effect
  --------------------------------------------------------
  Version 1.2.20041121a
  Dependencies: GIF/PNG images (0 through 4.gif/png)
  Code by Scott Schiller - www.schillmania.com
  --------------------------------------------------------
  Description:

  Initializes after body onload() by default (via addEventHandler() call at bottom.)

  Properties:

  usePNG
  ---------------
  Enables PNG images if supported ("false" disables all PNG usage)

  flakeTypes
  ---------------
  Sets the range of flake images to use (eg. a value of 5
  will use images ranging from 0.png to 4.png.)

  flakesMax
  ---------------
  Sets the maximum number of snowflakes that can exist on
  the screen at any given time.

  flakesMaxActive
  ---------------
  Sets the limit of "falling" snowflakes (ie. moving, thus
  considered to be "active".)

  vMax
  ---------------
  Defines the maximum X and Y velocities for the storm.
  A range up to this value is selected at random.

  flakeWidth
  ---------------
  The width (in pixels) of each snowflake image.

  flakeHeight
  ---------------
  Height (pixels) of each snowflake image.

  flakeBottom
  ---------------
  Limits the "bottom" coordinate of the snow.

  snowCollect
  ---------------
  Enables snow to pile up (slowly) at bottom of window.
  Can be very CPU/resource-intensive over time.

*/

var snowStorm = null;

function SnowStorm() {
 var s = this;
 var storm = this;
 this.timers = [];
 this.flakes = [];
 this.disabled = false;
 this.terrain = [];

 // User-configurable variables
 // ---------------------------

 var usePNG = false;
 var imagePath = 'image/snow/'; // relative path to snow images
 var flakeTypes = 6;
 var flakesMax = 128;
 var flakesMaxActive = 64;
 var vMax = 2.5;
 var flakeWidth = 5;
 var flakeHeight = 5;
 var flakeBottom = null; // Integer for fixed bottom, 0 or null for "full-screen" snow effect
 var snowCollect = false;
 var showStatus = true;

 // --- End of user section ---

 var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1);
 var isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1);
 var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera ')+1 || navigator.userAgent.toLowerCase().indexOf('opera/')+1);
 if (isOpera) isIE = false; // Opera (which is sneaky, pretending to be IE by default)
 var screenX = null;
 var screenY = null;
 var scrollY = null;
 var vRndX = null;
 var vRndY = null;

 function rnd(n,min) {
if (isNaN(min)) min = 0;
return (Math.random()*n)+min;
 }

 this.randomizeWind = function() {
vRndX = plusMinus(rnd(vMax,0.2));
vRndY = rnd(vMax,0.2);
if (this.flakes) {
  for (var i=0; i<this.flakes.length; i++) {
	if (this.flakes[i].active) this.flakes[i].setVelocities();
  }
}
 }

 function plusMinus(n) {
return (parseInt(rnd(2))==1?n*-1:n);
 }

 this.resizeHandler = function() {
if (window.innerWidth || window.innerHeight) {
  screenX = window.innerWidth-(!isIE?24:2);
  screenY = (flakeBottom?flakeBottom:window.innerHeight);
} else {
  screenX = (document.documentElement.clientWidth||document.body.clientWidth||document.bo
dy.scrollWidth)-(!isIE?8:0);
  screenY = flakeBottom?flakeBottom:(document.documentElement.clientHeight||document.body.clientHeight||document.
body.scrollHeight);
}
s.scrollHandler();
 }

 this.scrollHandler = function() {
// "attach" snowflakes to bottom of window if no absolute bottom value was given
scrollY = (flakeBottom?0:parseInt(window.scrollY||document.documentElement.scrollTop||document.body.scrollTop));
if (isNaN(scrollY)) scrollY = 0; // Netscape 6 scroll fix
if (!flakeBottom && s.flakes) {
  for (var i=0; i<s.flakes.length; i++) {
	if (s.flakes[i].active == 0) s.flakes[i].stick();
  }
}
 }

 this.freeze = function() {
// pause animation
if (!s.disabled) {
  s.disabled = 1;
} else {
  return false;
}
if (!isWin9X) {
  clearInterval(s.timers);
} else {
  for (var i=0; i<s.timers.length; i++) {
	clearInterval(s.timers[i]);
  }
}
 }

 this.resume = function() {
if (s.disabled) {
   s.disabled = 0;
} else {
  return false;
}
s.timerInit();
 }

 this.stop = function() {
this.freeze();
for (var i=0; i<this.flakes.length; i++) {
  this.flakes[i].o.style.display = 'none';
}
removeEventHandler(window,'scroll',this.scrollHandler,false);
removeEventHandler(window,'resize',this.resizeHandler,false);
 }

 this.SnowFlake = function(parent,type,x,y) {
var s = this;
var storm = parent;
this.type = type;
this.x = x||parseInt(rnd(screenX-12));
this.y = (!isNaN(y)?y:-12);
this.vX = null;
this.vY = null;
this.vAmpTypes = [2.0,1.0,1.25,1.0,1.5,1.75]; // "amplification" for vX/vY (based on flake size/type)
this.vAmp = this.vAmpTypes[this.type];

this.active = 1;
this.o = document.createElement('img');
this.o.style.position = 'absolute';
this.o.style.width = flakeWidth+'px';
this.o.style.height = flakeHeight+'px';
this.o.style.fontSize = '1px'; // so IE keeps proper size
this.o.style.zIndex = 2;
this.o.src = imagePath+this.type+(pngHandler.supported && usePNG?'.png':'.gif');
document.body.appendChild(this.o);
if (pngHandler.supported && usePNG) pngHandler.transform(this.o);

this.refresh = function() {
  this.o.style.left = this.x+'px';
  this.o.style.top = this.y+'px';
}

this.stick = function() {
  s.o.style.top = (screenY+scrollY-flakeHeight-storm.terrain[Math.floor(this.x)])+'px';
  // called after relative left has been called
}

this.vCheck = function() {
  if (this.vX>=0 && this.vX<0.2) {
	this.vX = 0.2;
  } else if (this.vX<0 && this.vX>-0.2) {
	this.vX = -0.2;
  }
  if (this.vY>=0 && this.vY<0.2) {
	this.vY = 0.2;
  }
}

this.move = function() {
  this.x += this.vX;
  this.y += (this.vY*this.vAmp);
  this.refresh();

  if (this.vX && screenX-this.x<flakeWidth+this.vX) { // X-axis scroll check
	this.x = 0;
  } else if (this.vX<0 && this.x<0-flakeWidth) {
	this.x = screenX-flakeWidth; // flakeWidth;
  }
  var yDiff = screenY+scrollY-this.y-storm.terrain[Math.floor(this.x)];
  if (yDiff<flakeHeight) {
	this.active = 0;
	if (snowCollect) {
	  var height = [0.75,1.5,0.75];
	  for (var i=0; i<2; i++) {
		storm.terrain[Math.floor(this.x)+i+2] += height[i];
	  }
	}
	this.o.style.left = ((this.x-(!isIE?flakeWidth:0))/screenX*100)+'%'; // set "relative" left (change with resize)
	if (!flakeBottom) {
	  this.stick();
	}
  }
}

this.animate = function() {
  // main animation loop
  // move, check status, die etc.
  this.move();
}

this.setVelocities = function() {
  this.vX = vRndX+rnd(vMax*0.12,0.1);
  this.vY = vRndY+rnd(vMax*0.12,0.1);
}

this.recycle = function() {
  this.setVelocities();
  this.vCheck();
  this.x = parseInt(rnd(screenX-flakeWidth-1));
  this.y = parseInt(rnd(640)*-1)-flakeHeight;
  this.active = 1;
}

this.recycle(); // set up x/y coords etc.
this.refresh();

 }

 this.snow = function() {
var active = 0;
var used = 0;
var waiting = 0;
for (var i=this.flakes.length-1; i>0; i--) {
  if (this.flakes[i].active == 1) {
	this.flakes[i].animate();
	active++;
  } else if (this.flakes[i].active == 0) {
	used++;
  } else {
	waiting++;
  }
}
if (snowCollect && !waiting) { // !active && !waiting
  // create another batch of snow
  this.createSnow(flakesMaxActive,true);
}
if (active<flakesMaxActive) {
  with (this.flakes[parseInt(rnd(this.flakes.length))]) {
	if (!snowCollect && active == 0) {
	  recycle();
	} else if (active == -1) {
	  active = 1;
	}
  }
}
 }

 this.createSnow = function(limit,allowInactive) {
if (showStatus) window.status = 'Creating snow...';
for (var i=0; i<limit; i++) {
  this.flakes[this.flakes.length] = new this.SnowFlake(this,parseInt(rnd(flakeTypes)));
  if (allowInactive || i>flakesMaxActive) this.flakes[this.flakes.length-1].active = -1;
}
if (showStatus) window.status = '';
 }

 this.timerInit = function() {
this.timers = (!isWin9X?setInterval("snowStorm.snow()",20):[setInterval("snowStorm.snow()",75),setInterval("snowStorm.snow()",25)]);
 }

 this.init = function() {
for (var i=0; i<8192; i++) {
  this.terrain[i] = 0;
}
this.randomizeWind();
this.createSnow(snowCollect?flakesMaxActive:flakesMaxActive*2); // create initial batch
addEventHandler(window,'resize',this.resizeHandler,false);
addEventHandler(window,'scroll',this.scrollHandler,false);
// addEventHandler(window,'scroll',this.resume,false); // scroll does not cause window focus. (odd)
// addEventHandler(window,'blur',this.freeze,false);
// addEventHandler(window,'focus',this.resume,false);
this.timerInit();
 }

 this.resizeHandler(); // get screen coordinates

 if (screenX && screenY && !this.disabled) {
this.init();
 }

}

function snowStormInit() {
 setTimeout("snowStorm = new SnowStorm()",500);
}

// Generic addEventHandler() wrapper
// ---------------------------------
// A generic interface for adding DOM event handlers
// Version 1.2.20040404
//
// Code by Scott Schiller | schillmania.com
//
// Revision history:
// ---------------------------------
// v1.1.20031218: initial deploy
// v1.2.20040404: added post-load event check

var addEventHandler = null;
var removeEventHandler = null;

function postLoadEvent(eventType) {
 // test for adding an event to the body (which has already loaded) - if so, fire immediately
 return ((eventType.toLowerCase().indexOf('load')>=0) && document.body);
}

function addEventHandlerDOM(o,eventType,eventHandler,eventBubble) {
 if (!postLoadEvent(eventType)) {
o.addEventListener(eventType,eventHandler,eventBubble);
 } else {
eventHandler();
 }
}

function removeEventHandlerDOM(o,eventType,eventHandler,eventBubble) {
 o.removeEventListener(eventType,eventHandler,eventBubble);
}

function addEventHandlerIE(o,eventType,eventHandler) { // IE workaround
 if (!eventType.indexOf('on')+1) eventType = 'on'+eventType;
 if (!postLoadEvent(eventType)) {
o.attachEvent(eventType,eventHandler); // Note addition of "on" to event type
 } else {
eventHandler();
 }
}

function removeEventHandlerIE(o,eventType,eventHandler) {
 if (!eventType.indexOf('on')+1) eventType = 'on'+eventType;
 o.detachEvent(eventType,eventHandler);
}

function addEventHandlerOpera(o,eventType,eventHandler,eventBubble) {
 if (!postLoadEvent(eventType)) {
(o==window?document:o).addEventListener(eventType,eventHandler,eventBubble);
 } else {
eventHandler();
 }
}

function removeEventHandlerOpera(o,eventType,eventHandler,eventBubble) {
 (o==window?document:o).removeEventListener(eventType,eventHandler,eventBubble);
}

if (navigator.userAgent.toLowerCase().indexOf('opera ')+1 || navigator.userAgent.toLowerCase().indexOf('opera/')+1) {
 // opera is dumb at times.
 addEventHandler = addEventHandlerOpera;
 removeEventHandler = removeEventHandlerOpera;
} else if (document.addEventListener) { // DOM event handler method
 addEventHandler = addEventHandlerDOM;
 removeEventHandler = removeEventHandlerDOM;
} else if (document.attachEvent) { // IE event handler method
 addEventHandler = addEventHandlerIE;
 removeEventHandler = removeEventHandlerIE;
} else { // Neither "DOM level 2" (?) methods supported
 addEventHandler = function(o,eventType,eventHandler,eventBubble) {
o['on'+eventType] = eventHandler;
// Multiple events could be added here via array etc.
 }
 removeEventHandler = function(o,eventType,eventHandler,eventBubble) {}
}

// Safari 1.0 does not support window.scroll events - apparently netscape 6.0/6.2 and mozilla 1.4 also.
// Refer to events support table at http://www.quirksmode.org/js/events_compinfo.html

// -- end addEventHandler definition --

/*
  PNGHandler: Object-Oriented Javascript-based PNG wrapper
  --------------------------------------------------------
  Version 1.2.20040803
  Code by Scott Schiller - www.schillmania.com
  --------------------------------------------------------
  Description:
  Provides gracefully-degrading PNG functionality where
  PNG is supported natively or via filters (Damn you, IE!)
  Should work with PNGs as images and DIV background images.
  --------------------------------------------------------
  Revision history
  --------------------------------------------------------
  1.2
  - Added refresh() for changing PNG images under IE
  - Class extension: "scale" causes PNG to scale under IE
  --------------------------------------------------------
  Known bugs
  --------------------------------------------------------
  - ie:mac doesn't support PNG background images.
  - Safari doesn't support currentStyle() - can't parse BG
 via CSS (ie. for a DIV with a PNG background by class)

*/

function PNGHandler() {
 var self = this;

 this.na = navigator.appName.toLowerCase();
 this.nv = navigator.appVersion.toLowerCase();
 this.isIE = this.na.indexOf('internet explorer')+1?1:0;
 this.isWin = this.nv.indexOf('windows')+1?1:0;
 this.isIEMac = (this.isIE&&!this.isWin);
 this.isIEWin = (this.isIE&&this.isWin);
 this.ver = this.isIE?parseFloat(this.nv.split('msie ')[1]):parseFloat(this.nv);
 this.isMac = this.nv.indexOf('mac')+1?1:0;
 this.isOpera = (navigator.userAgent.toLowerCase().indexOf('opera ')+1 || navigator.userAgent.toLowerCase().indexOf('opera/')+1);
 if (this.isOpera) this.isIE = false; // Opera filter catch (which is sneaky, pretending to be IE by default)
 this.filterID = 'DXImageTransform.Microsoft.AlphaImageLoader';
 this.supported = false;
 this.transform = self.doNothing;

 this.filterMethod = function(o) {
// IE 5.5+ proprietary filter garbage (boo!)
// Create new element based on old one. Doesn't seem to render properly otherwise (due to filter?)
// use DOM "currentStyle" method, so rules inherited via CSS are picked up.
if (o.nodeName != 'IMG') {
  var b = o.currentStyle.backgroundImage.toString(); // parse out background image URL
  o.style.backgroundImage = 'none';
  // Parse out background image URL from currentStyle.
  var i1 = b.indexOf('url("')+5;
  var newSrc = b.substr(i1,b.length-i1-2).replace('.gif','.png'); // find first instance of ") after (", chop from string
  o.style.writingMode = 'lr-tb'; // Has to be applied so filter "has layout" and is displayed. Seriously. Refer to http://msdn.microsoft.com/workshop/author/filter/reference/filters/alphaimageloader.asp?frame=true
  o.style.filter = "progid:"+self.filterID+"(src='"+newSrc+"',sizingMethod='"+(o.className.indexOf('scale')+1?'scale':'crop')+"')";
} else if (o.nodeName == 'IMG') {
  var newSrc = o.getAttribute('src').replace('.gif','.png');
  // apply filter
  o.src = 'image/none.gif'; // get rid of image
  o.style.filter = "progid:"+self.filterID+"(src='"+newSrc+"',sizingMethod="+(o.className.indexOf('scale')+1?'scale':'crop')+"')";
  o.style.writingMode = 'lr-tb'; // Has to be applied so filter "has layout" and is displayed. Seriously. Refer to http://msdn.microsoft.com/workshop/author/filter/reference/filters/alphaimageloader.asp?frame=true
}
 }

 this.pngMethod = function(o) {
// Native transparency support. Easy to implement. (woo!)
bgImage = this.getBackgroundImage(o);
if (bgImage) {
  // set background image, replacing .gif
  o.style.backgroundImage = 'url('+bgImage.replace('.gif','.png')+')';
} else if (o.nodeName == 'IMG') {
  o.src = o.src.replace('.gif','.png');
} else if (!bgImage) {
  // no background image
}
 }

 this.getBackgroundImage = function(o) {
var b, i1; // background-related variables
var bgUrl = null;
if (o.nodeName != 'IMG' && !(this.isIE && this.isMac)) { // ie:mac PNG support broken for DIVs with PNG backgrounds
  if (document.defaultView) {
	if (document.defaultView.getComputedStyle) {
	  b = document.defaultView.getComputedStyle(o,'').getPropertyValue('background-image');
	  i1 = b.indexOf('url(')+4;
	  bgUrl = b.substr(i1,b.length-i1-1);
	} else {
	  // no computed style
	  return false;
	}
  } else {
	// no default view
	return false;
  }
}
return bgUrl;
 }

 this.doNothing = function() {}

 this.supportTest = function() {
// Determine method to use.
// IE 5.5+/win32: filter

if (this.isIE && this.isWin && this.ver >= 5.5) {
  // IE proprietary filter method (via DXFilter)
  self.transform = self.filterMethod;
} else if (!this.isIE && this.ver < 5) {
  // No PNG support or broken support
  // Leave existing content as-is
  self.transform = null;
  return false;
} else if (!this.isIE && this.ver >= 5 || (this.isIE && this.isMac && this.ver >= 5)) { // version 5+ browser (not IE), or IE:mac 5+
  self.transform = self.pngMethod;
} else {
  // Presumably no PNG support. GIF used instead.
  self.transform = null;
  return false;
}
return true;
 }

 this.init = function() {
this.supported = this.supportTest();
 }

}

function getElementsByClassName(className,oParent) {
 var doc = (oParent||document);
 var matches = [];
 var nodes = doc.all||doc.getElementsByTagName('*');
 for (var i=0; i<nodes.length; i++) {
if (nodes[i].className == className || nodes[i].className.indexOf(className)+1 || nodes[i].className.indexOf(className+' ')+1 || nodes[i].className.indexOf(' '+className)+1) {
  matches[matches.length] = nodes[i];
}
 }
 return matches; // kids, don't play with fire.;)
}

// Instantiate and initialize PNG Handler

var pngHandler = new PNGHandler();

pngHandler.init();


addEventHandler(window,'load',snowStormInit,false);

 

Второй варинт такой, но там снег елезаметный

//Snow - http://www.btinternet.com/~kurt.grigg/javascript

if  ((document.getElementById) && 
window.addEventListener || window.attachEvent){

(function(){

//Configure here.

var num = 30;   //Number of flakes
var timer = 30; //setTimeout speed. Varies on different comps
var enableinNS6 = 1 //Enable script in NS6/Mozilla? Snow animation could be slow in those browsers. (1=yes, 0=no).

//End.

var y = [];
var x = [];
var fall = [];
var theFlakes = [];
var sfs = [];
var step = [];
var currStep = [];
var h,w,r;
var d = document;
var pix = "px";
var domWw = (typeof window.innerWidth == "number");
var domSy = (typeof window.pageYOffset == "number");
var idx = d.getElementsByTagName('div').length;

if (d.documentElement.style && 
typeof d.documentElement.style.MozOpacity == "string")
num = 12;

for (i = 0; i < num; i++){
sfs[i] = Math.round(1 + Math.random() * 1);

document.write('<div id="flake'+(idx+i)+'" style="position:absolute;top:0px;left:0px;width:'
+sfs[i]+'px;height:'+sfs[i]+'px;background-color:#B4CEE9;font-size:'+sfs[i]+'px"><\/div>');

currStep[i] = 0;
fall[i] = (sfs[i] == 1)?
Math.round(2 + Math.random() * 2): Math.round(3 + Math.random() * 2);
step[i] = (sfs[i] == 1)?
0.05 + Math.random() * 0.1 : 0.05 + Math.random() * 0.05;
}


if (domWw) r = window;
else{ 
 if (d.documentElement && 
 typeof d.documentElement.clientWidth == "number" && 
 d.documentElement.clientWidth != 0)
 r = d.documentElement;
else{ 
 if (d.body && 
 typeof d.body.clientWidth == "number")
 r = d.body;
}
}


function winsize(){
var oh,sy,ow,sx,rh,rw;
if (domWw){
 if (d.documentElement && d.defaultView && 
 typeof d.defaultView.scrollMaxY == "number"){
 oh = d.documentElement.offsetHeight;
 sy = d.defaultView.scrollMaxY;
 ow = d.documentElement.offsetWidth;
 sx = d.defaultView.scrollMaxX;
 rh = oh-sy;
 rw = ow-sx;
}
else{
 rh = r.innerHeight;
 rw = r.innerWidth;
}
h = rh - 2;  
w = rw - 2; 
}
else{
h = r.clientHeight - 2; 
w = r.clientWidth - 2; 
}
}


function scrl(yx){
var y,x;
if (domSy){
y = r.pageYOffset;
x = r.pageXOffset;
}
else{
y = r.scrollTop;
x = r.scrollLeft;
}
return (yx == 0)?y:x;
}


function snow(){
var dy,dx;

for (i = 0; i < num; i++){
dy = fall[i];
dx = fall[i] * Math.cos(currStep[i]);

y[i]+=dy;
x[i]+=dx; 

if (x[i] >= w || y[i] >= h){
 y[i] = -10;
 x[i] = Math.round(Math.random() * w);
 fall[i] = (sfs[i] == 1)?
 Math.round(2 + Math.random() * 2): Math.round(3 + Math.random() * 2);
 step[i] = (sfs[i] == 1)?
 0.05 + Math.random() * 0.1 : 0.05 + Math.random() * 0.05;
}

theFlakes[i].top = y[i] + scrl(0) + pix;
theFlakes[i].left = x[i] + scrl(1) + pix;

currStep[i]+=step[i];
}
setTimeout(snow,timer);
}


function init(){
winsize();
for (i = 0; i < num; i++){
theFlakes[i] = document.getElementById("flake"+(idx+i)).style;
y[i] = Math.round(Math.random()*h);
x[i] = Math.round(Math.random()*w);
}
snow();
}


if (window.addEventListener){
window.addEventListener("resize",winsize,false);
window.addEventListener("load",init,false);
}  
else if (window.attachEvent){
window.attachEvent("onresize",winsize);
window.attachEvent("onload",init);
} 

})();
}//End.

Ссылка на комментарий
Поделиться на других сайтах

Скажу честно, я еще года 4 назад встречал отличный скрипт, в 5 раз меньший :D
вот и отлично. что встречал - осталось его тут запостить для тех, кому это надо
Ссылка на комментарий
Поделиться на других сайтах

перепробовал их кажеться с десяток, только и слышно от пользователей "Уберите это на йух пжалста"

 

не у всех машинки позволяют

Ссылка на комментарий
Поделиться на других сайтах

Подскажите, а куда вставлять этот скрипт? Версия форума 1.3final

Какой этот?

Ссылка на комментарий
Поделиться на других сайтах

В шаблон форума сразу под тег <body> вставить код скрипта. Только, если используются имиджи снежинок - проверить путь к файлу: чтобы был или абсолютный, или относительный от корня форума.
Ссылка на комментарий
Поделиться на других сайтах

<script type="text/javascript">

/******************************************
* Snow Effect Script- By Altan d.o.o. (http://www.altan.hr/snow/index.html)
* Visit Dynamic Drive DHTML code library (http://www.dynamicdrive.com/) for full source code
* Last updated Nov 9th, 05' by DD. This notice must stay intact for use
******************************************/

 //Configure below to change URL path to the snow image
 var snowsrc="style_images/noel/snow.gif"
 // Configure below to change number of snow to render
 var no = 10;
 // Configure whether snow should disappear after x seconds (0=never):
 var hidesnowtime = 0;
 // Configure how much snow should drop down before fading ("windowheight" or "pageheight")
 var snowdistance = "pageheight";

///////////Stop Config//////////////////////////////////

 var ie4up = (document.all) ? 1 : 0;
 var ns6up = (document.getElementById&&!document.all) ? 1 : 0;

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

 var dx, xp, yp;	// coordinate and position variables
 var am, stx, sty;  // amplitude and step variables
 var i, doc_width = 800, doc_height = 600; 

 if (ns6up) {
doc_width = self.innerWidth;
doc_height = self.innerHeight;
 } else if (ie4up) {
doc_width = iecompattest().clientWidth;
doc_height = iecompattest().clientHeight;
 }

 dx = new Array();
 xp = new Array();
 yp = new Array();
 am = new Array();
 stx = new Array();
 sty = new Array();
 snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : snowsrc
 for (i = 0; i < no; ++ i) {  
dx[i] = 0;						// set coordinate variables
xp[i] = Math.random()*(doc_width-50);  // set position variables
yp[i] = Math.random()*doc_height;
am[i] = Math.random()*20;		 // set amplitude variables
stx[i] = 0.02 + Math.random()/10; // set step variables
sty[i] = 0.7 + Math.random();	 // set step variables
	if (ie4up||ns6up) {
  if (i == 0) {
	document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><a href=\"http://dynamicdrive.com\"><img src='"+snowsrc+"' border=\"0\"><\/a><\/div>");
  } else {
	document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowsrc+"' border=\"0\"><\/div>");
  }
}
 }

 function snowIE_NS6() {  // IE and NS6 main animation function
doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
	doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
for (i = 0; i < no; ++ i) {  // iterate for every dot
  yp[i] += sty[i];
  if (yp[i] > doc_height-50) {
	xp[i] = Math.random()*(doc_width-am[i]-30);
	yp[i] = 0;
	stx[i] = 0.02 + Math.random()/10;
	sty[i] = 0.7 + Math.random();
  }
  dx[i] += stx[i];
  document.getElementById("dot"+i).style.top=yp[i]+"px";
  document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
}
snowtimer=setTimeout("snowIE_NS6()", 10);
 }

function hidesnow(){
	if (window.snowtimer) clearTimeout(snowtimer)
	for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
}


if (ie4up||ns6up){
snowIE_NS6();
	if (hidesnowtime>0)
	setTimeout("hidesnow()", hidesnowtime*1000)
	}

</script>

 

Взято из скина Noel (http://www.invisionpower.fr). Работает в IE, FF2. Не грузит локальную машину.

Ссылка на комментарий
Поделиться на других сайтах

Скрипт снега, что мне так нравился (от FatCat) сильно грузил компы у пользователей + страница дергалась.

 

Сейчас этот, что предложил vAlex_ буду пробовать. Посмотрим, что скажут пользователи.

 

Стоп.

 

Все конечно хорошо, но нужно, чтобы снежинки были текстовыми, как было в варианте FatCat'a. Если кто может, исправьте, плз.

Ссылка на комментарий
Поделиться на других сайтах

Скрипт на который я дал ссылку, там можно установить любой символ в виде снежинки. Кстати, есть алгоритмы для того, чтобы такие скрипты не грузили машину.
Ссылка на комментарий
Поделиться на других сайтах

А как они, простите, их грузят?

Ява код, который компилится - копеечный, или у Вас Ваши юзвери сидят на 286х?

 

Простите за оффтопик.

Ссылка на комментарий
Поделиться на других сайтах

А как они, простите, их грузят?

Ява код, который компилится - копеечный, или у Вас Ваши юзвери сидят на 286х?

 

Простите за оффтопик.

Здесь не то, что явой не пахнет - тут даже апплета нет..

Ссылка на комментарий
Поделиться на других сайтах

  • 2 недели спустя...
А может есть у кого скриптик, чтоб снежинка (или несколько) просто вокруг курсора крутилась - простенько и со вкусом + тормозить не будет :D
Ссылка на комментарий
Поделиться на других сайтах

Тормозить будет все равно, только меньше.

Но я тебе скажу, лучше такие скрипты не ставить. Либо давать возможность юзерам отключать их.

Ссылка на комментарий
Поделиться на других сайтах

Aliance spb

 

Это не сильно будет тормозить, т.к. проявляться будет только там где курсор (а снег когда в десятке окон идёт - вешает мою систему нафиг). Пользователи наоборот хотят чегонибудь такого - новогоднего))) Кому не нравится могут JS отрубить...

Ссылка на комментарий
Поделиться на других сайтах

Image0=new Image();

Image0.src="http://fantasyflash.ru/script/web/image/sneg3.gif";

 

grphcs=new Array(1)

grphcs[0]="http://fantasyflash.ru/script/web/image/sneg3.gif"

 

Ypos=new Array();

Xpos=new Array();

Speed=new Array();

Step=new Array();

Cstep=new Array();

ns=(document.layers)?1:0;

if (ns){

for (i = 0; i < Amount; i++){

var P=Math.floor(Math.random()*grphcs.length);

rndPic=grphcs[P];

document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src="+rndPic+"></LAYER>");

}

}

else{

document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');

for (i = 0; i < Amount; i++){

var P=Math.floor(Math.random()*grphcs.length);

rndPic=grphcs[P];

document.write('<img id="si" src="'+rndPic+'" style="position:absolute;top:0px;left:0px">');

}

document.write('</div></div>');

}

WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;

WinWidth=(document.layers)?window.innerWidth:window.document.body.clientWidth;

for (i=0; i < Amount; i++){

Ypos = Math.round(Math.random()*WinHeight);

Xpos = Math.round(Math.random()*WinWidth);

Speed= Math.random()*3+2;

Cstep=0;//osw

Step=Math.random()*0.1+0.05;

}//fantasyflash.ru

function fall(){

var WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;

var WinWidth=(document.layers)?window.innerWidth:window.document.body.clientWidth;

var hscrll=(document.layers)?window.pageYOffset:document.body.scrollTop;

var wscrll=(document.layers)?window.pageXOffset:document.body.scrollLeft;

for (i=0; i < Amount; i++){

sy = Speed*Math.sin(90*Math.PI/180);

sx = Speed*Math.cos(Cstep);

Ypos+=sy;//osw

Xpos+=sx;

if (Ypos > WinHeight){

Ypos=-60;

Xpos=Math.round(Math.random()*WinWidth);

Speed=Math.random()*5+2;

}

if (ns){

document.layers['sn'+i].left=Xpos;

document.layers['sn'+i].top=Ypos+hscrll;

}

else{

si.style.pixelLeft=Xpos;

si.style.pixelTop=Ypos+hscrll;

}

Cstep+=Step;

}

setTimeout('fall()',35);

}

fall()

</SCRIPT>

Потом добавил так же еще скриптик курсора снеговика шаблон , не тормозит

(два скина , поставил на один скин скриптик снежинок )

Изменено пользователем Roman Borisovich
Ссылка на комментарий
Поделиться на других сайтах

Присоединиться к обсуждению

Вы можете ответить сейчас, а зарегистрироваться позже. Если у вас уже есть аккаунт, войдите, чтобы ответить от своего имени.

Гость
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Ответить в этой теме...

×   Вы вставили отформатированный текст.   Удалить форматирование

  Допустимо не более 75 смайлов.

×   Ваша ссылка была автоматически заменена на медиа-контент.   Отображать как ссылку

×   Ваши публикации восстановлены.   Очистить редактор

×   Вы не можете вставить изображения напрямую. Загрузите или вставьте изображения по ссылке.

Зарузка...
×
×
  • Создать...

Важная информация

Находясь на нашем сайте, вы соглашаетесь на использование файлов cookie, а также с нашим положением о конфиденциальности Политика конфиденциальности и пользовательским соглашением Условия использования.