-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.jSparks-1.0.js
64 lines (64 loc) · 1.57 KB
/
jquery.jSparks-1.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*!
* jSparks v1.0 by Arturo Campos [arturo025@gmail.com]
* http://almendraestudio.com/
*
* Date: Tue Jul 19 22:30:0 2011 -0600
*/
(function($) {
$.fn.jSparks = function(options) {
// Default options
var defaults = {
boxHeight: 100,
boxWidth: 100,
easing: 'swing',
maxZIndex: 20,
pointX: 0,
pointY: 0,
randomSpeed: true,
speed: 1500,
sparks: []
},
// Extend options based on user provided options
options = $.extend({}, defaults, options),
// Creates a new pair of coordinates
newPoint = function() {
options.pointX = random(options.boxWidth);
options.pointY = random(options.boxHeight);
},
// Creates a new random speed
newSpeed = function() {
options.speed = (random(5) + 5) * 250;
},
// Returns a random value
random = function(max) {
return Math.ceil(Math.random() * max) - 1;
},
// Animates the spark
fly = function(el) {
if (options.randomSpeed === true) {
newSpeed();
}
newPoint();
el.animate({
"top": options.pointY,
"left": options.pointX
}, options.speed, 'swing', function() {
fly(el);
});
};
return this.each(function() {
var $container = $(this);
options.boxHeight = $container.outerHeight(true);
options.boxWidth = $container.outerWidth(true);
// Creates a new image DOM Object for each spark
$.each(options.sparks, function(i, val) {
$spark = $('<img />');
$spark.attr('src', val).css('z-index', random(options.maxZIndex));
// Append it to the container
$container.append($spark);
// Make it fly!
fly($spark);
});
});
};
})(jQuery);