Autor |
wastas
Administrator
![Administrator Administrator](http://t0.gstatic.com/images?q=tbn:BOBU3MJKEZ2C6M:http://forum.pspoland.pl/download/file.php%3Favatar%3D92048_1261574651.jpg)
Dołączył: 21 Kwi 2010
Posty: 430
Przeczytał: 0 tematów
Pomógł: 2 razy Ostrzeżeń: 0/100 Skąd: nie mieszkam nigdzie Płeć: ![shinigani shinigani](http://t1.gstatic.com/images?q=tbn:n9tRRssN4fDlYM:http://th03.deviantart.net/fs40/300W/i/2009/050/5/5/Bleach__Burning_Out_Ichigo_by_mazjojo.jpg)
Pią 14:11, 20 Sie 2010
|
|
Wiadomość |
|
(function($){
$.snowfall = function(element, options){
var defaults = {
flakeCount : 50,
flakeColor : 'white',
flakeIndex: 200,
minSize : 2,
maxSize : 5,
minSpeed : 3,
maxSpeed : 10
},
options = $.extend(defaults, options),
random = function random(min, max){
return Math.round(min + Math.random()*(max-min));
};
$(element).data("snowfall", this);
function Flake(_x, _y, _size, _speed, _id)
{
this.id = _id;
this.jenów = _x;
this.y = _y;
this.size = _size;
this.speed = _speed;
this.step = 0,
this.stepSize = random(1,10) / 100;
var flakeMarkup = $(document.createElement("div")).attr({'class': 'snowfall-flakes', 'id' : 'flake-' + this.id}).css({'width' : this.size, 'height' : this.size, 'background' : options.flakeColor, 'position' : 'absolute', 'top' : this.y, 'left' : this.jenów, 'fontSize' : 0, 'zIndex' : options.flakeIndex});
if($(element).get(0).tagName === $(document).get(0).tagName){
$('body').append(flakeMarkup);
}else{
$(element).append(flakeMarkup);
}
this.element = document.getElementById('flake-' + this.id);
this.update = function(){
this.y += this.speed;
if(this.y > (elHeight) - 6){
this.reset();
}
this.element.style.top = this.y + 'px';
this.element.style.left = this.jenów + 'px';
this.step += this.stepSize;
this.jenów += Math.cos(this.step);
if(this.jenów > (elWidth) - 6 || this.jenów < 6){
this.reset();
}
}
this.reset = function(){
this.y = 0;
this.jenów = random(0, elWidth);
this.stepSize = random(1,10) / 100;
this.size = random((options.minSize * 100), (options.maxSize * 100)) / 100;
this.speed = random(options.minSpeed, options.maxSpeed);
}
}
var flakes = [],
flakeId = 0,
i = 0,
elHeight = $(element).height(),
elWidth = $(element).width();
$(window).bind("resize", function(){
elHeight = $(element).height();
elWidth = $(element).width();
});
for(i = 0; i < options.flakeCount; i+=1){
flakeId = flakes.length;
flakes.push(new Flake(random(0,elWidth), random(0, elHeight), random((options.minSize * 100), (options.maxSize * 100)) / 100, random(options.minSpeed, options.maxSpeed), flakeId));
}
function snow(){
for( i = 0; i < flakes.length; i += 1){
flakes[i].update();
}
setTimeout(function(){snow()}, 30);
}
snow();
this.clear = function(){
$(element).children('.snowfall-flakes').remove();
flakes = [];
};
};
$.fn.snowfall = function(options){
if(typeof(options) == "object"){
return this.each(function(i){
(new $.snowfall(this, options));
});
}else if (typeof(options) == "string") {
return this.each(function(i){
var snow = $(this).data('snowfall');
if(snow){
snow.clear();
}
});
}
};
})(jQuery);
$('#ground').snowfall({flakeCount : 100, maxSpeed : 10});
Post został pochwalony 0 razy
|
|